diff --git a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs
index 2cc64977..943a6b9d 100644
--- a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs
+++ b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs
@@ -191,6 +191,19 @@ namespace Newtonsoft.Json.Tests
}
}
+ [JsonObject(MemberSerialization.OptIn)]
+ public class Person
+ {
+ [JsonProperty]
+ public string Name { get; set; }
+
+ [JsonProperty]
+ public DateTime BirthDate { get; set; }
+
+ // not serialized
+ public string Department { get; set; }
+ }
+
public class JsonSerializerTest : TestFixtureBase
{
[Test]
diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
index 86eccf66..19642d5f 100644
--- a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
@@ -167,8 +167,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(true, (bool)new JValue(true));
Assert.AreEqual(true, (bool?)new JValue(true));
Assert.AreEqual(null, (bool?)((JValue)null));
- Assert.AreEqual(null, (bool?)JValue.Null);
- Assert.AreEqual(null, (bool?)JValue.Undefined);
+ Assert.AreEqual(null, (bool?)new JValue((object)null));
Assert.AreEqual(10, (long)new JValue(10));
Assert.AreEqual(null, (long?)new JValue((long?)null));
Assert.AreEqual(null, (long?)(JValue)null);
diff --git a/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs b/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs
index 2e110123..3027b12d 100644
--- a/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs
@@ -30,18 +30,39 @@ using System.Drawing;
namespace Newtonsoft.Json.Converters
{
+ ///
+ /// Converts a object to and from JSON.
+ ///
public class HtmlColorConverter : JsonConverter
{
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
public override void WriteJson(JsonWriter writer, object value)
{
writer.WriteValue(ColorTranslator.ToHtml((Color)value));
}
+ ///
+ /// Determines whether this instance can convert the specified value type.
+ ///
+ /// Type of the value.
+ ///
+ /// true if this instance can convert the specified value type; otherwise, false.
+ ///
public override bool CanConvert(Type valueType)
{
return typeof(Color).IsAssignableFrom(valueType);
}
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
public override object ReadJson(JsonReader reader, Type objectType)
{
throw new NotImplementedException();
diff --git a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
index 7a1a6ce3..4b30f82d 100644
--- a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs
@@ -7,18 +7,30 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Converters
{
+ ///
+ /// Converts text in the ISO 8601 date format to and from JSON.
+ ///
public class IsoDateTimeConverter : JsonConverter
{
private const string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
+ ///
+ /// Gets or sets the date time styles used when converting a date to and from JSON.
+ ///
+ /// The date time styles used when converting a date to and from JSON.
public DateTimeStyles DateTimeStyles
{
get { return _dateTimeStyles; }
set { _dateTimeStyles = value; }
}
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
public override void WriteJson(JsonWriter writer, object value)
{
string text;
@@ -46,6 +58,12 @@ namespace Newtonsoft.Json.Converters
writer.WriteValue(text);
}
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
public override object ReadJson(JsonReader reader, Type objectType)
{
if (reader.TokenType != JsonToken.String)
@@ -59,6 +77,13 @@ namespace Newtonsoft.Json.Converters
return DateTime.Parse(dateText, CultureInfo.InvariantCulture, _dateTimeStyles);
}
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
public override bool CanConvert(Type objectType)
{
return (typeof(DateTime).IsAssignableFrom(objectType)
diff --git a/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs
index 3b569596..12b8cd1a 100644
--- a/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs
@@ -7,8 +7,16 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Converters
{
+ ///
+ /// Converts a to and from a JavaScript date constructor (e.g. new Date(52231943)).
+ ///
public class JavaScriptDateTimeConverter : JsonConverter
{
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
public override void WriteJson(JsonWriter writer, object value)
{
long ticks;
@@ -31,6 +39,12 @@ namespace Newtonsoft.Json.Converters
writer.WriteEndConstructor();
}
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
public override object ReadJson(JsonReader reader, Type objectType)
{
if (reader.TokenType != JsonToken.StartConstructor || string.Compare(reader.Value.ToString(), "Date", StringComparison.Ordinal) != 0)
@@ -56,6 +70,13 @@ namespace Newtonsoft.Json.Converters
return d;
}
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
public override bool CanConvert(Type objectType)
{
return (typeof(DateTime).IsAssignableFrom(objectType)
diff --git a/Src/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs b/Src/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
index 4b9f3100..089b89d9 100644
--- a/Src/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
+++ b/Src/Newtonsoft.Json/Converters/JsonDateTimeSerializationMode.cs
@@ -5,11 +5,26 @@ using System.Text;
namespace Newtonsoft.Json.Converters
{
+ ///
+ /// Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC), or is not specified as either local time or UTC.
+ ///
public enum JsonDateTimeSerializationMode
{
+ ///
+ /// The time represented is local time.
+ ///
Local,
+ ///
+ /// The time represented is UTC.
+ ///
Utc,
+ ///
+ /// The time represented is not specified as either local time or Coordinated Universal Time (UTC).
+ ///
Unspecified,
+ ///
+ /// Preserves the DateTimeKind field of a date when a DateTime object is converted to a string and the string is then converted back to a DateTime object.
+ ///
RoundtripKind
}
}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs
index bac427d8..ffe23cea 100644
--- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs
@@ -33,6 +33,9 @@ using System.Linq;
namespace Newtonsoft.Json.Converters
{
+ ///
+ /// Converts an XmlNode to and from JSON.
+ ///
public class XmlNodeConverter : JsonConverter
{
private const string TextName = "#text";
@@ -44,6 +47,11 @@ namespace Newtonsoft.Json.Converters
private const string JsonNamespaceUri = "http://james.newtonking.com/projects/json";
#region Writing
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
public override void WriteJson(JsonWriter writer, object value)
{
XmlNode node = value as XmlNode;
@@ -245,6 +253,12 @@ namespace Newtonsoft.Json.Converters
#endregion
#region Reading
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
public override object ReadJson(JsonReader reader, Type objectType)
{
// maybe have CanReader and a CanWrite methods so this sort of test wouldn't be necessary
@@ -525,6 +539,13 @@ namespace Newtonsoft.Json.Converters
}
#endregion
+ ///
+ /// Determines whether this instance can convert the specified value type.
+ ///
+ /// Type of the value.
+ ///
+ /// true if this instance can convert the specified value type; otherwise, false.
+ ///
public override bool CanConvert(Type valueType)
{
return typeof(XmlNode).IsAssignableFrom(valueType);
diff --git a/Src/Newtonsoft.Json/Identifier.cs b/Src/Newtonsoft.Json/Identifier.cs
index b74df378..bccbe438 100644
--- a/Src/Newtonsoft.Json/Identifier.cs
+++ b/Src/Newtonsoft.Json/Identifier.cs
@@ -37,15 +37,26 @@ using System.ComponentModel;
namespace Newtonsoft.Json
{
+ ///
+ ///
+ ///
public class Identifier
{
private string _name;
+ ///
+ /// Gets the name.
+ ///
+ /// The name.
public string Name
{
get { return _name; }
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The name.
public Identifier(string name)
{
_name = name;
@@ -56,6 +67,14 @@ namespace Newtonsoft.Json
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
+ ///
+ /// Determines whether the specified is equal to the current .
+ ///
+ /// The to compare with the current .
+ ///
+ /// true if the specified is equal to the current ; otherwise, false.
+ ///
+ /// The parameter is null.
public override bool Equals(object obj)
{
Identifier function = obj as Identifier;
@@ -63,11 +82,22 @@ namespace Newtonsoft.Json
return Equals(function);
}
+ ///
+ /// Equalses the specified function.
+ ///
+ /// The function.
+ ///
public bool Equals(Identifier function)
{
return (_name == function.Name);
}
+ ///
+ /// Equalses the specified a.
+ ///
+ /// A.
+ /// The b.
+ ///
public static bool Equals(Identifier a, Identifier b)
{
if (a == b)
@@ -79,21 +109,45 @@ namespace Newtonsoft.Json
return false;
}
+ ///
+ /// Serves as a hash function for a particular type.
+ ///
+ ///
+ /// A hash code for the current .
+ ///
public override int GetHashCode()
{
return _name.GetHashCode();
}
+ ///
+ /// Returns a that represents the current .
+ ///
+ ///
+ /// A that represents the current .
+ ///
public override string ToString()
{
return _name;
}
+ ///
+ /// Implements the operator ==.
+ ///
+ /// A.
+ /// The b.
+ /// The result of the operator.
public static bool operator ==(Identifier a, Identifier b)
{
return Identifier.Equals(a, b);
}
+ ///
+ /// Implements the operator !=.
+ ///
+ /// A.
+ /// The b.
+ /// The result of the operator.
public static bool operator !=(Identifier a, Identifier b)
{
return !Identifier.Equals(a, b);
diff --git a/Src/Newtonsoft.Json/JavaScriptConvert.cs b/Src/Newtonsoft.Json/JavaScriptConvert.cs
index 5c628e16..a20c4dc5 100644
--- a/Src/Newtonsoft.Json/JavaScriptConvert.cs
+++ b/Src/Newtonsoft.Json/JavaScriptConvert.cs
@@ -117,7 +117,7 @@ namespace Newtonsoft.Json
return ToStringInternal(value, DateTimeKind.Local);
}
- public static string ToStringInternal(DateTimeOffset value, DateTimeKind kind)
+ internal static string ToStringInternal(DateTimeOffset value, DateTimeKind kind)
{
long javaScriptTicks = ConvertDateTimeToJavaScriptTicks(value);
@@ -388,15 +388,21 @@ namespace Newtonsoft.Json
}
///
- /// Serializes the specified object to a Json object.
+ /// Serializes the specified object to a JSON string.
///
/// The object to serialize.
- /// A Json string representation of the object.
+ /// A JSON string representation of the object.
public static string SerializeObject(object value)
{
return SerializeObject(value, null);
}
+ ///
+ /// Serializes the specified object to a JSON string using a collection of .
+ ///
+ /// The object to serialize.
+ /// A collection converters used while serializing.
+ /// A JSON string representation of the object.
public static string SerializeObject(object value, params JsonConverter[] converters)
{
StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
@@ -468,7 +474,7 @@ namespace Newtonsoft.Json
}
///
- /// Deserializes the specified object to a Json object.
+ /// Deserializes the JSON string to the specified type.
///
/// The type of the object to deserialize.
/// The object to deserialize.
@@ -479,6 +485,13 @@ namespace Newtonsoft.Json
return (T)DeserializeObject(value, typeof(T), converters);
}
+ ///
+ /// Deserializes the JSON string to the specified type.
+ ///
+ /// The object to deserialize.
+ /// The type of the object to deserialize.
+ /// Converters to use while deserializing.
+ /// The deserialized object from the JSON string.
public static object DeserializeObject(string value, Type type, params JsonConverter[] converters)
{
StringReader sr = new StringReader(value);
@@ -502,6 +515,11 @@ namespace Newtonsoft.Json
return deserializedValue;
}
+ ///
+ /// Serializes the XML node to a JSON string.
+ ///
+ /// The node to serialize.
+ /// A JSON string of the XmlNode.
public static string SerializeXmlNode(XmlNode node)
{
XmlNodeConverter converter = new XmlNodeConverter();
@@ -509,6 +527,11 @@ namespace Newtonsoft.Json
return SerializeObject(node, converter);
}
+ ///
+ /// Deserializes the XmlNode from a JSON string.
+ ///
+ /// The JSON string.
+ /// The deserialized XmlNode
public static XmlNode DeserializeXmlNode(string value)
{
XmlNodeConverter converter = new XmlNodeConverter();
diff --git a/Src/Newtonsoft.Json/JsonConverter.cs b/Src/Newtonsoft.Json/JsonConverter.cs
index 5877d2b6..1bc9f11a 100644
--- a/Src/Newtonsoft.Json/JsonConverter.cs
+++ b/Src/Newtonsoft.Json/JsonConverter.cs
@@ -30,10 +30,33 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json
{
+ ///
+ /// Converts an object to and from JSON.
+ ///
public abstract class JsonConverter
{
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
public abstract void WriteJson(JsonWriter writer, object value);
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The object value.
public abstract object ReadJson(JsonReader reader, Type objectType);
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
public abstract bool CanConvert(Type objectType);
}
}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/JsonConverterCollection.cs b/Src/Newtonsoft.Json/JsonConverterCollection.cs
index b19ab761..a2a2bea5 100644
--- a/Src/Newtonsoft.Json/JsonConverterCollection.cs
+++ b/Src/Newtonsoft.Json/JsonConverterCollection.cs
@@ -30,6 +30,9 @@ using System.Collections.ObjectModel;
namespace Newtonsoft.Json
{
+ ///
+ /// Represents a collection of .
+ ///
public class JsonConverterCollection : Collection
{
}
diff --git a/Src/Newtonsoft.Json/JsonIgnoreAttribute.cs b/Src/Newtonsoft.Json/JsonIgnoreAttribute.cs
index 8262998c..f736c8c1 100644
--- a/Src/Newtonsoft.Json/JsonIgnoreAttribute.cs
+++ b/Src/Newtonsoft.Json/JsonIgnoreAttribute.cs
@@ -29,6 +29,9 @@ using System.Text;
namespace Newtonsoft.Json
{
+ ///
+ /// Instructs the not to serialize the public field or public read/write property value.
+ ///
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
public sealed class JsonIgnoreAttribute : Attribute
{
diff --git a/Src/Newtonsoft.Json/JsonObjectAttribute.cs b/Src/Newtonsoft.Json/JsonObjectAttribute.cs
index 0c172cae..568b71e9 100644
--- a/Src/Newtonsoft.Json/JsonObjectAttribute.cs
+++ b/Src/Newtonsoft.Json/JsonObjectAttribute.cs
@@ -30,21 +30,35 @@ using System.Text;
namespace Newtonsoft.Json
{
+ ///
+ /// Instructs the how to serialize the object.
+ ///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
public sealed class JsonObjectAttribute : Attribute
{
private MemberSerialization _memberSerialization = MemberSerialization.OptOut;
+ ///
+ /// Gets or sets the member serialization.
+ ///
+ /// The member serialization.
public MemberSerialization MemberSerialization
{
get { return _memberSerialization; }
set { _memberSerialization = value; }
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
public JsonObjectAttribute()
{
}
+ ///
+ /// Initializes a new instance of the class with the specified member serialization.
+ ///
+ /// The member serialization.
public JsonObjectAttribute(MemberSerialization memberSerialization)
{
MemberSerialization = memberSerialization;
diff --git a/Src/Newtonsoft.Json/JsonPropertyAttribute.cs b/Src/Newtonsoft.Json/JsonPropertyAttribute.cs
index a22f041e..e6049ea8 100644
--- a/Src/Newtonsoft.Json/JsonPropertyAttribute.cs
+++ b/Src/Newtonsoft.Json/JsonPropertyAttribute.cs
@@ -2,21 +2,35 @@ using System;
namespace Newtonsoft.Json
{
+ ///
+ /// Instructs the to always serialize the member with the specified name.
+ ///
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
public sealed class JsonPropertyAttribute : Attribute
{
private string _propertyName;
+ ///
+ /// Gets or sets the name of the property.
+ ///
+ /// The name of the property.
public string PropertyName
{
get { return _propertyName; }
set { _propertyName = value; }
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
public JsonPropertyAttribute()
{
}
+ ///
+ /// Initializes a new instance of the class with the specified name.
+ ///
+ /// Name of the property.
public JsonPropertyAttribute(string propertyName)
{
_propertyName = propertyName;
diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs
index 7844eb64..00898abd 100644
--- a/Src/Newtonsoft.Json/JsonReader.cs
+++ b/Src/Newtonsoft.Json/JsonReader.cs
@@ -39,20 +39,62 @@ namespace Newtonsoft.Json
///
public abstract class JsonReader : IDisposable
{
+ ///
+ /// Specifies the state of the reader.
+ ///
protected enum State
{
+ ///
+ /// The Read method has not been called.
+ ///
Start,
+ ///
+ /// The end of the file has been reached successfully.
+ ///
Complete,
+ ///
+ /// Reader is at a property.
+ ///
Property,
+ ///
+ /// Reader is at the start of an object.
+ ///
ObjectStart,
+ ///
+ /// Reader is in an object.
+ ///
Object,
+ ///
+ /// Reader is at the start of an array.
+ ///
ArrayStart,
+ ///
+ /// Reader is in an array.
+ ///
Array,
+ ///
+ /// The Close method has been called.
+ ///
Closed,
+ ///
+ /// Reader has just read a value.
+ ///
PostValue,
+ ///
+ /// Reader is at the start of a constructor.
+ ///
ConstructorStart,
+ ///
+ /// Reader in a constructor.
+ ///
Constructor,
+ ///
+ /// An error occurred that prevents the read operation from continuing.
+ ///
Error,
+ ///
+ /// The end of the file has been reached successfully.
+ ///
Finished
}
@@ -63,6 +105,10 @@ namespace Newtonsoft.Json
private char _quoteChar;
private State _currentState;
+ ///
+ /// Gets the current reader state.
+ ///
+ /// The current reader state.
protected State CurrentState
{
get { return _currentState; }
@@ -106,6 +152,10 @@ namespace Newtonsoft.Json
get { return _valueType; }
}
+ ///
+ /// Gets the depth of the current token in the JSON document.
+ ///
+ /// The depth of the current token in the JSON document.
public int Depth
{
get
@@ -156,6 +206,9 @@ namespace Newtonsoft.Json
///
public abstract bool Read();
+ ///
+ /// Skips the children of the current token.
+ ///
public void Skip()
{
if (IsStartToken(TokenType))
@@ -168,11 +221,20 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Sets the current token.
+ ///
+ /// The new token.
protected void SetToken(JsonToken newToken)
{
SetToken(newToken, null);
}
+ ///
+ /// Sets the current token and value.
+ ///
+ /// The new token.
+ /// The value.
protected virtual void SetToken(JsonToken newToken, object value)
{
_token = newToken;
@@ -242,6 +304,9 @@ namespace Newtonsoft.Json
throw new JsonReaderException("JsonToken {0} is not valid for closing JsonType {1}.".FormatWith(CultureInfo.InvariantCulture, endToken, currentObject));
}
+ ///
+ /// Sets the state based on current token type.
+ ///
protected void SetStateBasedOnCurrent()
{
JsonTokenType currentObject = Peek();
@@ -315,6 +380,10 @@ namespace Newtonsoft.Json
Dispose(true);
}
+ ///
+ /// Releases unmanaged and - optionally - managed resources
+ ///
+ /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
if (_currentState != State.Closed && disposing)
diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs
index 431ef99e..62bcf659 100644
--- a/Src/Newtonsoft.Json/JsonSerializer.cs
+++ b/Src/Newtonsoft.Json/JsonSerializer.cs
@@ -97,6 +97,10 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Gets or sets how objects are created.
+ ///
+ /// The object creation handling.
public ObjectCreationHandling ObjectCreationHandling
{
get { return _objectCreationHandling; }
@@ -109,6 +113,10 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Gets a collection that will be used during serialization.
+ ///
+ /// Collection that will be used during serialization.
public JsonConverterCollection Converters
{
get
@@ -146,7 +154,7 @@ namespace Newtonsoft.Json
/// Deserializes the Json structure contained by the specified
/// into an instance of the specified type.
///
- /// The type of object to create.
+ /// The containing the object.
/// The of object being deserialized.
/// The instance of being deserialized.
public object Deserialize(JsonReader reader, Type objectType)
@@ -163,6 +171,13 @@ namespace Newtonsoft.Json
return CreateJToken(reader);
}
+ ///
+ /// Deserializes the Json structure contained by the specified
+ /// into an instance of the specified type.
+ ///
+ /// The containing the object.
+ /// The of object being deserialized.
+ /// The instance of being deserialized.
public object Deserialize(StringReader reader, Type objectType)
{
return Deserialize(new JsonTextReader(reader), objectType);
@@ -351,6 +366,11 @@ namespace Newtonsoft.Json
return memberMappings;
}
+ ///
+ /// Gets the serializable members for the given .
+ ///
+ /// The object to get seralizable members for.
+ /// Seralizable members for the given type.
protected virtual List GetSerializableMembers(Type objectType)
{
return ReflectionUtils.GetFieldsAndProperties(objectType, BindingFlags.Public | BindingFlags.Instance);
diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs
index d846123f..6e533925 100644
--- a/Src/Newtonsoft.Json/JsonTextReader.cs
+++ b/Src/Newtonsoft.Json/JsonTextReader.cs
@@ -147,6 +147,11 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Sets the current token and value.
+ ///
+ /// The new token.
+ /// The value.
protected override void SetToken(JsonToken newToken, object value)
{
base.SetToken(newToken, value);
@@ -787,7 +792,7 @@ namespace Newtonsoft.Json
}
///
- /// Changes the to Closed.
+ /// Changes the to Closed.
///
public override void Close()
{
diff --git a/Src/Newtonsoft.Json/JsonTextWriter.cs b/Src/Newtonsoft.Json/JsonTextWriter.cs
index d7ff55f0..19c04088 100644
--- a/Src/Newtonsoft.Json/JsonTextWriter.cs
+++ b/Src/Newtonsoft.Json/JsonTextWriter.cs
@@ -145,6 +145,10 @@ namespace Newtonsoft.Json
_writer.Write("[");
}
+ ///
+ /// Writes the start of a constructor with the given name.
+ ///
+ /// The name of the constructor.
public override void WriteStartConstructor(string name)
{
base.WriteStartConstructor(name);
@@ -154,6 +158,10 @@ namespace Newtonsoft.Json
_writer.Write("(");
}
+ ///
+ /// Writes the specified end token.
+ ///
+ /// The end token to write.
protected override void WriteEnd(JsonToken token)
{
switch (token)
@@ -191,6 +199,9 @@ namespace Newtonsoft.Json
_writer.Write(':');
}
+ ///
+ /// Writes indent characters.
+ ///
protected override void WriteIndent()
{
if (Formatting == Formatting.Indented)
@@ -208,11 +219,17 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Writes the JSON value delimiter.
+ ///
protected override void WriteValueDelimiter()
{
_writer.Write(',');
}
+ ///
+ /// Writes an indent space.
+ ///
protected override void WriteIndentSpace()
{
_writer.Write(' ');
diff --git a/Src/Newtonsoft.Json/JsonWriter.cs b/Src/Newtonsoft.Json/JsonWriter.cs
index 05061143..3367d0ee 100644
--- a/Src/Newtonsoft.Json/JsonWriter.cs
+++ b/Src/Newtonsoft.Json/JsonWriter.cs
@@ -81,7 +81,7 @@ namespace Newtonsoft.Json
///
None,
///
- /// Causes child objects to be indented according to the and settings.
+ /// Causes child objects to be indented according to the and settings.
///
Indented
}
@@ -136,6 +136,10 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Gets the top.
+ ///
+ /// The top.
protected int Top
{
get { return _top; }
@@ -183,9 +187,8 @@ namespace Newtonsoft.Json
}
///
- /// Creates an instance of the JsonWriter class using the specified .
+ /// Creates an instance of the JsonWriter class.
///
- /// The TextWriter to write to.
public JsonWriter()
{
_stack = new List(1);
@@ -263,12 +266,19 @@ namespace Newtonsoft.Json
AutoCompleteClose(JsonToken.EndArray);
}
+ ///
+ /// Writes the start of a constructor with the given name.
+ ///
+ /// The name of the constructor.
public virtual void WriteStartConstructor(string name)
{
AutoComplete(JsonToken.StartConstructor);
Push(JsonTokenType.Constructor);
}
+ ///
+ /// Writes the end constructor.
+ ///
public void WriteEndConstructor()
{
AutoCompleteClose(JsonToken.EndConstructor);
@@ -291,6 +301,10 @@ namespace Newtonsoft.Json
WriteEnd(Peek());
}
+ ///
+ /// Writes the current token.
+ ///
+ /// The to read the token from.
public void WriteToken(JsonReader reader)
{
ValidationUtils.ArgumentNotNull(reader, "reader");
@@ -473,18 +487,31 @@ namespace Newtonsoft.Json
}
}
+ ///
+ /// Writes the specified end token.
+ ///
+ /// The end token to write.
protected virtual void WriteEnd(JsonToken token)
{
}
+ ///
+ /// Writes indent characters.
+ ///
protected virtual void WriteIndent()
{
}
+ ///
+ /// Writes the JSON value delimiter.
+ ///
protected virtual void WriteValueDelimiter()
{
}
+ ///
+ /// Writes an indent space.
+ ///
protected virtual void WriteIndentSpace()
{
}
diff --git a/Src/Newtonsoft.Json/Linq/Extensions.cs b/Src/Newtonsoft.Json/Linq/Extensions.cs
index 02ea7e9a..555be12f 100644
--- a/Src/Newtonsoft.Json/Linq/Extensions.cs
+++ b/Src/Newtonsoft.Json/Linq/Extensions.cs
@@ -33,8 +33,17 @@ using System.Globalization;
namespace Newtonsoft.Json.Linq
{
+ ///
+ /// Contains the LINQ to JSON extension methods.
+ ///
public static class Extensions
{
+ ///
+ /// Returns a collection of tokens that contains the ancestors of every token in the source collection.
+ ///
+ /// The type of the objects in source, constrained to .
+ /// An of that contains the source collection.
+ /// An of that contains the ancestors of every node in the source collection.
public static IEnumerable Ancestors(this IEnumerable source) where T : JToken
{
ValidationUtils.ArgumentNotNull(source, "source");
@@ -50,6 +59,12 @@ namespace Newtonsoft.Json.Linq
// return source.SelectMany(j => j.AncestorsAndSelf());
//}
+ ///
+ /// Returns a collection of tokens that contains the descendants of every token in the source collection.
+ ///
+ /// The type of the objects in source, constrained to .
+ /// An of that contains the source collection.
+ /// An of that contains the descendants of every node in the source collection.
public static IEnumerable Descendants(this IEnumerable source) where T : JContainer
{
ValidationUtils.ArgumentNotNull(source, "source");
@@ -65,6 +80,11 @@ namespace Newtonsoft.Json.Linq
// return source.SelectMany(j => j.DescendantsAndSelf());
//}
+ ///
+ /// Returns a collection of child properties of every object in the source collection.
+ ///
+ /// An of that contains the source collection.
+ /// An of that contains the properties of every object in the source collection.
public static IEnumerable Properties(this IEnumerable source)
{
ValidationUtils.ArgumentNotNull(source, "source");
@@ -72,21 +92,45 @@ namespace Newtonsoft.Json.Linq
return source.SelectMany(d => d.Properties());
}
+ ///
+ /// Returns a collection of child values of every object in the source collection with the given key.
+ ///
+ /// An of that contains the source collection.
+ /// The token key.
+ /// An of that contains the values of every node in the source collection with the given key.
public static IEnumerable Values(this IEnumerable source, object key)
{
return Values(source, key);
}
+ ///
+ /// Returns a collection of child values of every object in the source collection.
+ ///
+ /// An of that contains the source collection.
+ /// An of that contains the values of every node in the source collection.
public static IEnumerable Values(this IEnumerable source)
{
return Values(source, null);
}
+ ///
+ /// Returns a collection of converted child values of every object in the source collection with the given key.
+ ///
+ /// The type to convert the values to.
+ /// An of that contains the source collection.
+ /// The token key.
+ /// An that contains the converted values of every node in the source collection with the given key.
public static IEnumerable Values(this IEnumerable source, object key)
{
return Values(source, key);
}
+ ///
+ /// Returns a collection of converted child values of every object in the source collection.
+ ///
+ /// The type to convert the values to.
+ /// An of that contains the source collection.
+ /// An that contains the converted values of every node in the source collection.
public static IEnumerable Values(this IEnumerable source)
{
return Values(source, null);
@@ -142,11 +186,21 @@ namespace Newtonsoft.Json.Linq
// return source.SelectMany(c => c.Children());
//}
+ ///
+ /// Returns a collection of child tokens of every array in the source collection.
+ ///
+ /// An of that contains the source collection.
+ /// An of that contains the values of every node in the source collection.
public static IEnumerable Children(this IEnumerable source)
{
return Children(source);
}
+ ///
+ /// Returns a collection of converted child tokens of every array in the source collection.
+ ///
+ /// An of that contains the source collection.
+ /// An of that contains the converted values of every node in the source collection.
public static IEnumerable Children(this IEnumerable source)
{
ValidationUtils.ArgumentNotNull(source, "source");
@@ -193,10 +247,7 @@ namespace Newtonsoft.Json.Linq
}
}
-
//TODO
//public static void Remove(this IEnumerable source) where T : JContainer;
-
-
}
}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs
index a35c4677..9af09fd2 100644
--- a/Src/Newtonsoft.Json/Linq/JArray.cs
+++ b/Src/Newtonsoft.Json/Linq/JArray.cs
@@ -33,27 +33,49 @@ using System.Globalization;
namespace Newtonsoft.Json.Linq
{
+ ///
+ /// Represents a JSON array.
+ ///
public class JArray : JContainer
{
+ ///
+ /// Gets the node type for this .
+ ///
+ /// The type.
public override JsonTokenType Type
{
get { return JsonTokenType.Array; }
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
public JArray()
{
}
+ ///
+ /// Initializes a new instance of the class from another object.
+ ///
+ /// A object to copy from.
public JArray(JArray other)
: base(other)
{
}
+ ///
+ /// Initializes a new instance of the class with the specified content.
+ ///
+ /// The contents of the array.
public JArray(params object[] content)
: this((object)content)
{
}
+ ///
+ /// Initializes a new instance of the class with the specified content.
+ ///
+ /// The contents of the array.
public JArray(object content)
{
Add(content);
@@ -70,11 +92,20 @@ namespace Newtonsoft.Json.Linq
return new JArray(this);
}
+ ///
+ /// Returns a count of this token's child tokens.
+ ///
+ ///
public int Count()
{
return Children().Count();
}
+ ///
+ /// Loads an from a .
+ ///
+ /// A that will be read for the content of the .
+ /// A that contains the XML that was read from the specified .
public static JArray Load(JsonReader reader)
{
if (reader.TokenType == JsonToken.None)
@@ -98,6 +129,11 @@ namespace Newtonsoft.Json.Linq
return a;
}
+ ///
+ /// Load a from a string that contains JSON.
+ ///
+ /// A that contains JSON.
+ /// A populated from the string that contains JSON.
public static JArray Parse(string json)
{
JsonReader jsonReader = new JsonTextReader(new StringReader(json));
@@ -113,6 +149,11 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
}
+ ///
+ /// Creates a from an object.
+ ///
+ /// The object that will be used to create .
+ /// A with the values of the specified object
public static JArray FromObject(object o)
{
JToken token = FromObjectInternal(o);
@@ -123,6 +164,11 @@ namespace Newtonsoft.Json.Linq
return (JArray)token;
}
+ ///
+ /// Writes this token to a .
+ ///
+ /// A into which this method will write.
+ /// A collection of which will be used when writing the token.
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartArray();
@@ -135,6 +181,10 @@ namespace Newtonsoft.Json.Linq
writer.WriteEndArray();
}
+ ///
+ /// Gets the with the specified key.
+ ///
+ /// The with the specified key.
public override JToken this[object key]
{
get
diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs
index 8c41c424..16836375 100644
--- a/Src/Newtonsoft.Json/Linq/JConstructor.cs
+++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs
@@ -32,10 +32,17 @@ using System.Globalization;
namespace Newtonsoft.Json.Linq
{
+ ///
+ /// Represents a JSON constructor.
+ ///
public class JConstructor : JContainer
{
private string _name;
+ ///
+ /// Gets or sets the name of this constructor.
+ ///
+ /// The constructor name.
public string Name
{
get { return _name; }
@@ -51,27 +58,48 @@ namespace Newtonsoft.Json.Linq
get { return JsonTokenType.Constructor; }
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
public JConstructor()
{
}
+ ///
+ /// Initializes a new instance of the class from another object.
+ ///
+ /// A object to copy from.
public JConstructor(JConstructor other)
: base(other)
{
_name = other.Name;
}
+ ///
+ /// Initializes a new instance of the class with the specified name and content.
+ ///
+ /// The constructor name.
+ /// The contents of the constructor.
public JConstructor(string name, params object[] content)
: this(name, (object)content)
{
}
+ ///
+ /// Initializes a new instance of the class with the specified name and content.
+ ///
+ /// The constructor name.
+ /// The contents of the constructor.
public JConstructor(string name, object content)
: this(name)
{
Add(content);
}
+ ///
+ /// Initializes a new instance of the class with the specified name.
+ ///
+ /// The constructor name.
public JConstructor(string name)
{
_name = name;
@@ -116,6 +144,10 @@ namespace Newtonsoft.Json.Linq
writer.WriteEndConstructor();
}
+ ///
+ /// Gets the with the specified key.
+ ///
+ /// The with the specified key.
public override JToken this[object key]
{
get
diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs
index edc0f1bf..16eb532e 100644
--- a/Src/Newtonsoft.Json/Linq/JContainer.cs
+++ b/Src/Newtonsoft.Json/Linq/JContainer.cs
@@ -34,6 +34,9 @@ using System.Globalization;
namespace Newtonsoft.Json.Linq
{
+ ///
+ /// Represents a token that can contain other tokens.
+ ///
public abstract class JContainer : JToken
{
private JToken _content;
@@ -44,15 +47,11 @@ namespace Newtonsoft.Json.Linq
set { _content = value; }
}
- protected JContainer()
+ internal JContainer()
{
}
- ///
- /// Initializes a new instance of the class from another object.
- ///
- /// A object to copy from.
- protected JContainer(JContainer other)
+ internal JContainer(JContainer other)
{
ValidationUtils.ArgumentNotNull(other, "c");
@@ -105,6 +104,12 @@ namespace Newtonsoft.Json.Linq
while (true);
}
+ ///
+ /// Get the first child token of this token.
+ ///
+ ///
+ /// A containing the first child token of the .
+ ///
public override JToken First
{
get
@@ -116,6 +121,12 @@ namespace Newtonsoft.Json.Linq
}
}
+ ///
+ /// Get the last child token of this token.
+ ///
+ ///
+ /// A containing the last child token of the .
+ ///
public override JToken Last
{
[DebuggerStepThrough]
@@ -160,13 +171,10 @@ namespace Newtonsoft.Json.Linq
return Children().Convert();
}
- //public override T Value(object key)
- //{
- // JToken token = this[key];
-
- // return Extensions.Convert(token);
- //}
-
+ ///
+ /// Returns a collection of the descendant tokens for this token in document order.
+ ///
+ /// An containing the descendant tokens of the .
public IEnumerable Descendants()
{
foreach (JToken o in Children())
@@ -266,17 +274,25 @@ namespace Newtonsoft.Json.Linq
throw new Exception("Can not add {0} to {1}".FormatWith(CultureInfo.InvariantCulture, o.GetType(), GetType()));
}
+ ///
+ /// Adds the specified content as children of this .
+ ///
+ /// The content to be added.
public virtual void Add(object content)
{
AddInternal(true, Last, content);
}
+ ///
+ /// Adds the specified content as the first children of this .
+ ///
+ /// The content to be added.
public void AddFirst(object content)
{
AddInternal(false, Last, content);
}
- protected JToken CreateFromContent(object content)
+ internal JToken CreateFromContent(object content)
{
if (content is JToken)
return (JToken)content;
@@ -284,17 +300,28 @@ namespace Newtonsoft.Json.Linq
return new JValue(content);
}
+ ///
+ /// Creates an that can be used to add tokens to the .
+ ///
+ /// An that is ready to have content written to it.
public JsonWriter CreateWriter()
{
return new JsonTokenWriter(this);
}
+ ///
+ /// Replaces the children nodes of this token with the specified content.
+ ///
+ /// The content.
public void ReplaceAll(object content)
{
RemoveAll();
Add(content);
}
+ ///
+ /// Removes the child nodes from this token.
+ ///
public void RemoveAll()
{
while (_content != null)
@@ -417,10 +444,10 @@ namespace Newtonsoft.Json.Linq
parent.AddObjectSkipNotify(JValue.CreateComment(r.Value.ToString()));
break;
case JsonToken.Null:
- parent.AddObjectSkipNotify(JValue.Null);
+ parent.AddObjectSkipNotify(new JValue(null, JsonTokenType.Null));
break;
case JsonToken.Undefined:
- parent.AddObjectSkipNotify(JValue.Undefined);
+ parent.AddObjectSkipNotify(new JValue(null, JsonTokenType.Undefined));
break;
case JsonToken.PropertyName:
JProperty property = new JProperty(r.Value.ToString());
diff --git a/Src/Newtonsoft.Json/Linq/JEnumerable.cs b/Src/Newtonsoft.Json/Linq/JEnumerable.cs
index 8e549289..3762ef93 100644
--- a/Src/Newtonsoft.Json/Linq/JEnumerable.cs
+++ b/Src/Newtonsoft.Json/Linq/JEnumerable.cs
@@ -7,12 +7,23 @@ using System.Collections;
namespace Newtonsoft.Json.Linq
{
+ ///
+ /// Represents a collection of objects.
+ ///
+ /// The type of token
public struct JEnumerable : IEnumerable where T : JToken
{
+ ///
+ /// An empty collection of objects.
+ ///
public static readonly JEnumerable Empty = new JEnumerable(Enumerable.Empty());
private IEnumerable _enumerable;
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The enumerable.
public JEnumerable(IEnumerable enumerable)
{
ValidationUtils.ArgumentNotNull(enumerable, "enumerable");
@@ -20,16 +31,32 @@ namespace Newtonsoft.Json.Linq
_enumerable = enumerable;
}
+ ///
+ /// Returns an enumerator that iterates through the collection.
+ ///
+ ///
+ /// A that can be used to iterate through the collection.
+ ///
public IEnumerator GetEnumerator()
{
return _enumerable.GetEnumerator();
}
+ ///
+ /// Returns an enumerator that iterates through a collection.
+ ///
+ ///
+ /// An object that can be used to iterate through the collection.
+ ///
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
+ ///
+ /// Gets the with the specified key.
+ ///
+ ///
public IEnumerable this[object key]
{
get { return Extensions.Values(_enumerable, key); }
diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs
index c597b63f..f8540a0b 100644
--- a/Src/Newtonsoft.Json/Linq/JObject.cs
+++ b/Src/Newtonsoft.Json/Linq/JObject.cs
@@ -54,11 +54,19 @@ namespace Newtonsoft.Json.Linq
{
}
+ ///
+ /// Initializes a new instance of the class with the specified content.
+ ///
+ /// The contents of the object.
public JObject(params object[] content)
: this((object)content)
{
}
+ ///
+ /// Initializes a new instance of the class with the specified content.
+ ///
+ /// The contents of the object.
public JObject(object content)
{
Add(content);
@@ -83,16 +91,29 @@ namespace Newtonsoft.Json.Linq
return new JObject(this);
}
+ ///
+ /// Gets the node type for this .
+ ///
+ /// The type.
public override JsonTokenType Type
{
get { return JsonTokenType.Object; }
}
+ ///
+ /// Gets an of this object's properties.
+ ///
+ /// An of this object's properties.
public IEnumerable Properties()
{
return Children().Cast();
}
+ ///
+ /// Gets a the specified name.
+ ///
+ /// The property name.
+ /// A with the specified name or null.
public JProperty Property(string name)
{
return Properties()
@@ -100,21 +121,19 @@ namespace Newtonsoft.Json.Linq
.SingleOrDefault();
}
+ ///
+ /// Gets an of this object's property values.
+ ///
+ /// An of this object's property values.
public JEnumerable PropertyValues()
{
return new JEnumerable(Properties().Select(p => p.Value));
}
- //public override void Add(object content)
- //{
- // ValidationUtils.ArgumentNotNull(content, "content");
-
- // if (!(content is JProperty) && !IsMultiContent(content))
- // throw new ArgumentException("Error adding {0} to JObject. JObject only supports JProperty content.".FormatWith(CultureInfo.InvariantCulture, content.GetType().Name));
-
- // base.Add(content);
- //}
-
+ ///
+ /// Gets the with the specified key.
+ ///
+ /// The with the specified key.
public override JToken this[object key]
{
get
@@ -131,6 +150,11 @@ namespace Newtonsoft.Json.Linq
}
}
+ ///
+ /// Loads an from a .
+ ///
+ /// A that will be read for the content of the .
+ /// A that contains the XML that was read from the specified .
public static JObject Load(JsonReader reader)
{
ValidationUtils.ArgumentNotNull(reader, "reader");
@@ -156,6 +180,11 @@ namespace Newtonsoft.Json.Linq
return o;
}
+ ///
+ /// Load a from a string that contains JSON.
+ ///
+ /// A that contains JSON.
+ /// A populated from the string that contains JSON.
public static JObject Parse(string json)
{
JsonReader jsonReader = new JsonTextReader(new StringReader(json));
@@ -163,6 +192,11 @@ namespace Newtonsoft.Json.Linq
return Load(jsonReader);
}
+ ///
+ /// Creates a from an object.
+ ///
+ /// The object that will be used to create .
+ /// A with the values of the specified object
public static JObject FromObject(object o)
{
JToken token = FromObjectInternal(o);
@@ -181,6 +215,11 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
}
+ ///
+ /// Writes this token to a .
+ ///
+ /// A into which this method will write.
+ /// A collection of which will be used when writing the token.
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartObject();
diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs
index 5e6de856..b75a345d 100644
--- a/Src/Newtonsoft.Json/Linq/JToken.cs
+++ b/Src/Newtonsoft.Json/Linq/JToken.cs
@@ -140,6 +140,10 @@ namespace Newtonsoft.Json.Linq
}
}
+ internal JToken()
+ {
+ }
+
///
/// Returns a collection of the ancestor tokens of this token.
///
diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs
index c6eb2bd8..de2469db 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.cs
@@ -32,55 +32,87 @@ using System.Globalization;
namespace Newtonsoft.Json.Linq
{
+ ///
+ /// Represents a value in JSON (string, integer, date, etc).
+ ///
public class JValue : JToken
{
private JsonTokenType _valueType;
private object _value;
- public static readonly JValue Null = new JValue(null, JsonTokenType.Null);
- public static readonly JValue Undefined = new JValue(null, JsonTokenType.Undefined);
-
- private JValue(object value, JsonTokenType type)
+ internal JValue(object value, JsonTokenType type)
{
_value = value;
_valueType = type;
}
- public JValue(JValue value)
- : this(value.Value, value.Type)
+ ///
+ /// Initializes a new instance of the class from another object.
+ ///
+ /// A object to copy from.
+ public JValue(JValue other)
+ : this(other.Value, other.Type)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(long value)
: this(value, JsonTokenType.Integer)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(ulong value)
: this(value, JsonTokenType.Integer)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(double value)
: this(value, JsonTokenType.Float)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(DateTime value)
: this(value, JsonTokenType.Date)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(bool value)
: this(value, JsonTokenType.Boolean)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(string value)
: this(value, JsonTokenType.String)
{
}
+ ///
+ /// Initializes a new instance of the class with the given value.
+ ///
+ /// The value.
public JValue(object value)
: this(value, GetValueType(null, value))
{
@@ -95,12 +127,18 @@ namespace Newtonsoft.Json.Linq
return (this == other || (_valueType == other.Type && Compare(_value, other.Value)));
}
+ ///
+ /// Gets a value indicating whether this token has childen tokens.
+ ///
+ ///
+ /// true if this token has child values; otherwise, false.
+ ///
public override bool HasValues
{
get { return false; }
}
- public bool Compare(object objA, object objB)
+ private bool Compare(object objA, object objB)
{
if (objA == null && objB == null)
return true;
@@ -130,11 +168,26 @@ namespace Newtonsoft.Json.Linq
return new JValue(this);
}
+ ///
+ /// Creates a comment with the given value.
+ ///
+ /// The value.
+ ///
public static JValue CreateComment(string value)
{
return new JValue(value, JsonTokenType.Comment);
}
+ ///
+ /// Creates a string with the given value.
+ ///
+ /// The value.
+ ///
+ public static JValue CreateString(string value)
+ {
+ return new JValue(value, JsonTokenType.String);
+ }
+
private static JsonTokenType GetValueType(JsonTokenType? current, object value)
{
if (value == null)
@@ -154,11 +207,19 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentException("Could not determin JSON object type for type {0}.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
}
+ ///
+ /// Gets the node type for this .
+ ///
+ /// The type.
public override JsonTokenType Type
{
get { return _valueType; }
}
+ ///
+ /// Gets or sets the underlying token value.
+ ///
+ /// The underlying token value.
public object Value
{
get { return _value; }
@@ -174,11 +235,6 @@ namespace Newtonsoft.Json.Linq
}
}
- public static JValue CreateString(string value)
- {
- return new JValue(value, JsonTokenType.String);
- }
-
private static void WriteConvertableValue(JsonWriter writer, IList converters, Action