Files
Newtonsoft.Json/Src/Newtonsoft.Json/JsonRaw.cs
T
JamesNK 5bb0c17eec -Renamed Identifier to JsonRaw
-Added support for reading, writing and serializing raw JSON
2008-09-27 23:37:55 +00:00

121 lines
4.1 KiB
C#

#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.ComponentModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json
{
/// <summary>
/// Raw JSON content.
/// </summary>
public class JsonRaw
{
private string _content;
/// <summary>
/// Gets the raw JSON string.
/// </summary>
/// <value>The raw JSON string.</value>
public string Content
{
get { return _content; }
}
/// <summary>
/// Initializes a new instance of the <see cref="JsonRaw"/> class.
/// </summary>
/// <param name="content">The content.</param>
public JsonRaw(string content)
{
ValidationUtils.ArgumentNotNull(content, "content");
_content = content;
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
/// </summary>
/// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
/// <returns>
/// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
/// </returns>
/// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
public override bool Equals(object obj)
{
JsonRaw raw = obj as JsonRaw;
if (raw == null)
return false;
return (string.Compare(_content, raw.Content, StringComparison.OrdinalIgnoreCase) == 0);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return _content.GetHashCode();
}
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </returns>
public override string ToString()
{
return _content;
}
/// <summary>
/// Creates an instance of <see cref="JsonRaw"/> with the content of the reader's current token.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>An instance of <see cref="JsonRaw"/> with the content of the reader's current token.</returns>
public static JsonRaw Create(JsonReader reader)
{
using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.WriteToken(reader);
return new JsonRaw(sw.ToString());
}
}
}
}