-Added some XML comments
-Made some utility methods internal
This commit is contained in:
@@ -305,5 +305,28 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LongStringTest()
|
||||
{
|
||||
int length = 20000;
|
||||
string json = @"[""" + new string(' ', length) + @"""]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
Assert.AreEqual(20000, reader.Value.ToString().Length);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,6 +307,9 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
||||
@@ -42,6 +42,10 @@ namespace Newtonsoft.Json.Linq
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node type for this <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
/// <value>The type.</value>
|
||||
public override JsonTokenType Type
|
||||
{
|
||||
get { return JsonTokenType.Constructor; }
|
||||
@@ -95,6 +99,11 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes this token to a <see cref="JsonWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
|
||||
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
|
||||
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
|
||||
{
|
||||
writer.WriteStartConstructor(_name);
|
||||
|
||||
@@ -48,6 +48,10 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JContainer"/> class from another <see cref="JContainer"/> object.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="JContainer"/> object to copy from.</param>
|
||||
protected JContainer(JContainer other)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(other, "c");
|
||||
@@ -64,6 +68,12 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this token has childen tokens.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this token has child values; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public override bool HasValues
|
||||
{
|
||||
get { return (_content != null); }
|
||||
@@ -112,6 +122,12 @@ namespace Newtonsoft.Json.Linq
|
||||
get { return _content; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the child tokens of this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> containing the child tokens of this <see cref="JToken"/>, in document order.
|
||||
/// </returns>
|
||||
public override JEnumerable<JToken> Children()
|
||||
{
|
||||
return new JEnumerable<JToken>(ChildrenInternal());
|
||||
@@ -132,6 +148,13 @@ namespace Newtonsoft.Json.Linq
|
||||
&& ((current = current.Next) != null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the child values of this token, in document order.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns>
|
||||
/// A <see cref="IEnumerable{T}"/> containing the child values of this <see cref="JToken"/>, in document order.
|
||||
/// </returns>
|
||||
public override IEnumerable<T> Values<T>()
|
||||
{
|
||||
return Children().Convert<JToken, T>();
|
||||
|
||||
@@ -33,12 +33,22 @@ using System.Globalization;
|
||||
|
||||
namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a JSON object.
|
||||
/// </summary>
|
||||
public class JObject : JContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JObject"/> class.
|
||||
/// </summary>
|
||||
public JObject()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JObject"/> class from another <see cref="JObject"/> object.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="JObject"/> object to copy from.</param>
|
||||
public JObject(JObject other)
|
||||
: base(other)
|
||||
{
|
||||
|
||||
@@ -33,26 +33,38 @@ using System.Globalization;
|
||||
|
||||
namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a JSON property.
|
||||
/// </summary>
|
||||
public class JProperty : JContainer
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property name.
|
||||
/// </summary>
|
||||
/// <value>The property name.</value>
|
||||
public string Name
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the property value.
|
||||
/// </summary>
|
||||
/// <value>The property value.</value>
|
||||
public JToken Value
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get { return Last; }
|
||||
set
|
||||
{
|
||||
ReplaceAll(value);
|
||||
}
|
||||
set { ReplaceAll(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JProperty"/> class from another <see cref="JProperty"/> object.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="JProperty"/> object to copy from.</param>
|
||||
public JProperty(JProperty other)
|
||||
: base(other)
|
||||
{
|
||||
@@ -70,12 +82,20 @@ namespace Newtonsoft.Json.Linq
|
||||
return new JProperty(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node type for this <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
/// <value>The type.</value>
|
||||
public override JsonTokenType Type
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get { return JsonTokenType.Property; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JProperty"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The property name.</param>
|
||||
public JProperty(string name)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(name, "name");
|
||||
@@ -83,6 +103,11 @@ namespace Newtonsoft.Json.Linq
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JProperty"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The property name.</param>
|
||||
/// <param name="value">The property value.</param>
|
||||
public JProperty(string name, object value)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNullOrEmpty(name, "name");
|
||||
@@ -99,6 +124,11 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes this token to a <see cref="JsonWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
|
||||
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
|
||||
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
|
||||
{
|
||||
writer.WritePropertyName(_name);
|
||||
|
||||
@@ -34,11 +34,18 @@ using System.Globalization;
|
||||
|
||||
namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an abstract JSON token.
|
||||
/// </summary>
|
||||
public abstract class JToken
|
||||
{
|
||||
private JContainer _parent;
|
||||
internal JToken _next;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parent.
|
||||
/// </summary>
|
||||
/// <value>The parent.</value>
|
||||
public JContainer Parent
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
@@ -46,6 +53,10 @@ namespace Newtonsoft.Json.Linq
|
||||
internal set { _parent = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root <see cref="JToken"/> of this <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
/// <value>The root <see cref="JToken"/> of this <see cref="JToken"/>.</value>
|
||||
public JToken Root
|
||||
{
|
||||
get
|
||||
@@ -66,14 +77,35 @@ namespace Newtonsoft.Json.Linq
|
||||
internal abstract JToken CloneNode();
|
||||
internal abstract bool DeepEquals(JToken node);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node type for this <see cref="JToken"/>.
|
||||
/// </summary>
|
||||
/// <value>The type.</value>
|
||||
public abstract JsonTokenType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this token has childen tokens.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this token has child values; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public abstract bool HasValues { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Compares the values of two tokens, including the values of all descendant tokens.
|
||||
/// </summary>
|
||||
/// <param name="t1">The first <see cref="JToken"/> to compare.</param>
|
||||
/// <param name="t2">The second <see cref="JToken"/> to compare.</param>
|
||||
/// <returns>true if the tokens are equal; otherwise false.</returns>
|
||||
public static bool DeepEquals(JToken t1, JToken t2)
|
||||
{
|
||||
return (t1 == t2 || (t1 != null && t2 != null && t1.DeepEquals(t2)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next sibling token of this node.
|
||||
/// </summary>
|
||||
/// <value>The <see cref="JToken"/> that contains the next sibling token.</value>
|
||||
public JToken Next
|
||||
{
|
||||
get
|
||||
@@ -86,6 +118,10 @@ namespace Newtonsoft.Json.Linq
|
||||
internal set { _next = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the previous sibling token of this node.
|
||||
/// </summary>
|
||||
/// <value>The <see cref="JToken"/> that contains the previous sibling token.</value>
|
||||
public JToken Previous
|
||||
{
|
||||
get
|
||||
@@ -104,6 +140,10 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the ancestor tokens of this token.
|
||||
/// </summary>
|
||||
/// <returns>A collection of the ancestor tokens of this token.</returns>
|
||||
public IEnumerable<JToken> Ancestors()
|
||||
{
|
||||
for (JToken parent = Parent; parent != null; parent = parent.Parent)
|
||||
@@ -112,6 +152,10 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the sibling tokens after this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>A collection of the sibling tokens after this tokens, in document order.</returns>
|
||||
public IEnumerable<JToken> AfterSelf()
|
||||
{
|
||||
if (Parent == null)
|
||||
@@ -121,17 +165,31 @@ namespace Newtonsoft.Json.Linq
|
||||
yield return o;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the sibling tokens before this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>A collection of the sibling tokens before this token, in document order.</returns>
|
||||
public IEnumerable<JToken> BeforeSelf()
|
||||
{
|
||||
for (JToken o = Parent.First; o != this; o = o.Next)
|
||||
yield return o;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="JToken"/> with the specified key.
|
||||
/// </summary>
|
||||
/// <value>The <see cref="JToken"/> with the specified key.</value>
|
||||
public virtual JToken this[object key]
|
||||
{
|
||||
get { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="JToken"/> with the specified key converted to the specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to convert the token to.</typeparam>
|
||||
/// <param name="key">The token key.</param>
|
||||
/// <returns>The converted token value.</returns>
|
||||
public virtual T Value<T>(object key)
|
||||
{
|
||||
JToken token = this[key];
|
||||
@@ -139,40 +197,54 @@ namespace Newtonsoft.Json.Linq
|
||||
return Extensions.Convert<JToken, T>(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the first child token of this token.
|
||||
/// </summary>
|
||||
/// <value>A <see cref="JToken"/> containing the first child token of the <see cref="JToken"/>.</value>
|
||||
public virtual JToken First
|
||||
{
|
||||
get { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); }
|
||||
//get { return null; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the last child token of this token.
|
||||
/// </summary>
|
||||
/// <value>A <see cref="JToken"/> containing the last child token of the <see cref="JToken"/>.</value>
|
||||
public virtual JToken Last
|
||||
{
|
||||
get { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); }
|
||||
//get { return null; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the child tokens of this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> containing the child tokens of this <see cref="JToken"/>, in document order.</returns>
|
||||
public virtual JEnumerable<JToken> Children()
|
||||
{
|
||||
throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType()));
|
||||
//return JEnumerable<JToken>.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the child tokens of this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="JEnumerable{T}"/> containing the child tokens of this <see cref="JToken"/>, in document order.</returns>
|
||||
public JEnumerable<T> Children<T>() where T : JToken
|
||||
{
|
||||
return new JEnumerable<T>(Children().OfType<T>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the child values of this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="IEnumerable{T}"/> containing the child values of this <see cref="JToken"/>, in document order.</returns>
|
||||
public virtual IEnumerable<T> Values<T>()
|
||||
{
|
||||
throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType()));
|
||||
}
|
||||
|
||||
//public virtual IEnumerable<T> Children<T>()
|
||||
// {
|
||||
// throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType()));
|
||||
// //return Enumerable.Empty<T>();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Removes this token from its parent.
|
||||
/// </summary>
|
||||
public void Remove()
|
||||
{
|
||||
if (_parent == null)
|
||||
@@ -181,6 +253,10 @@ namespace Newtonsoft.Json.Linq
|
||||
_parent.Remove(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces this token with the specified token.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
public void Replace(JToken value)
|
||||
{
|
||||
if (_parent == null)
|
||||
@@ -202,13 +278,29 @@ namespace Newtonsoft.Json.Linq
|
||||
parent.AddInternal(isLast, previous, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes this token to a <see cref="JsonWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
|
||||
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
|
||||
public abstract void WriteTo(JsonWriter writer, params JsonConverter[] converters);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the indented JSON for this token.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:System.String"/> containing the indented JSON.
|
||||
/// </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return ToString(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the indented JSON for this token using any given converters.
|
||||
/// </summary>
|
||||
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
|
||||
/// <returns></returns>
|
||||
private string ToString(params JsonConverter[] converters)
|
||||
{
|
||||
using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
|
||||
@@ -271,6 +363,11 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
|
||||
#region Cast operators
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Boolean"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator bool(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -280,6 +377,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (bool)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.DateTimeOffset"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator DateTimeOffset(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -289,6 +391,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (DateTimeOffset)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Boolean}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator bool?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -301,6 +408,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (bool?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Int64"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator long(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -310,6 +422,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (long)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{DateTime}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator DateTime?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -322,6 +439,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (DateTime?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{DateTimeOffset}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator DateTimeOffset?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -334,6 +456,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (DateTimeOffset?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Decimal}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator decimal?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -346,6 +473,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (decimal?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Double}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator double?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -358,6 +490,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (double?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Int32"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator int(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -367,6 +504,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return Convert.ToInt32(v.Value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Int32}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator int?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -379,6 +521,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (v.Value != null) ? (int?)Convert.ToInt32(v.Value, CultureInfo.InvariantCulture) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.DateTime"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator DateTime(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -388,6 +535,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (DateTime)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Int64}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator long?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -400,6 +552,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (long?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{Single}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator float?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -412,6 +569,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (float?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator decimal(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -421,6 +583,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (decimal)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{UInt32}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator uint?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -433,6 +600,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (uint?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="Nullable{UInt64}"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator ulong?(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -445,6 +617,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (ulong?)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator double(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -454,6 +631,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (double)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator float(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -463,6 +645,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return Convert.ToSingle(v.Value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.String"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator string(JToken value)
|
||||
{
|
||||
if (value == null)
|
||||
@@ -475,6 +662,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return (string)v.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.UInt32"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator uint(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -484,6 +676,11 @@ namespace Newtonsoft.Json.Linq
|
||||
return Convert.ToUInt32(v.Value, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an explicit conversion from <see cref="Newtonsoft.Json.Linq.JToken"/> to <see cref="System.UInt64"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static explicit operator ulong(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
|
||||
@@ -109,11 +109,11 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
case JsonTokenType.Integer:
|
||||
if (objA is ulong || objB is ulong)
|
||||
return Convert.ToDecimal(objA).Equals(Convert.ToDecimal(objB));
|
||||
return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDecimal(objB, CultureInfo.InvariantCulture));
|
||||
else
|
||||
return Convert.ToInt64(objA).Equals(Convert.ToInt64(objB));
|
||||
return Convert.ToInt64(objA, CultureInfo.InvariantCulture).Equals(Convert.ToInt64(objB, CultureInfo.InvariantCulture));
|
||||
case JsonTokenType.Float:
|
||||
return Convert.ToDouble(objA).Equals(Convert.ToDouble(objB));
|
||||
return Convert.ToDouble(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDouble(objB, CultureInfo.InvariantCulture));
|
||||
case JsonTokenType.Comment:
|
||||
case JsonTokenType.String:
|
||||
case JsonTokenType.Boolean:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,7 +7,7 @@ using System.Globalization;
|
||||
|
||||
namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
public static class DateTimeUtils
|
||||
internal static class DateTimeUtils
|
||||
{
|
||||
public static string GetLocalOffset(this DateTime d)
|
||||
{
|
||||
|
||||
@@ -7,12 +7,12 @@ using System.Threading;
|
||||
|
||||
namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
public interface IWrappedDictionary : IDictionary
|
||||
internal interface IWrappedDictionary : IDictionary
|
||||
{
|
||||
object UnderlyingDictionary { get; }
|
||||
}
|
||||
|
||||
public class DictionaryWrapper<TKey, TValue> : IDictionary<TKey, TValue>, IWrappedDictionary
|
||||
internal class DictionaryWrapper<TKey, TValue> : IDictionary<TKey, TValue>, IWrappedDictionary
|
||||
{
|
||||
private readonly IDictionary _dictionary;
|
||||
private readonly IDictionary<TKey, TValue> _genericDictionary;
|
||||
|
||||
@@ -33,12 +33,12 @@ using System.Globalization;
|
||||
|
||||
namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
public interface IWrappedList : IList
|
||||
internal interface IWrappedList : IList
|
||||
{
|
||||
object UnderlyingList { get; }
|
||||
}
|
||||
|
||||
public class ListWrapper<T> : IList<T>, IWrappedList
|
||||
internal class ListWrapper<T> : IList<T>, IWrappedList
|
||||
{
|
||||
private readonly IList _list;
|
||||
private readonly IList<T> _genericList;
|
||||
|
||||
Reference in New Issue
Block a user