Merge branch 'master' into eisber-master
This commit is contained in:
@@ -27,7 +27,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Bson
|
||||
/// <param name="value">The <see cref="Object"/> value to write.</param>
|
||||
public override void WriteValue(object value)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
InternalWriteValue(JsonToken.Integer);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#endregion
|
||||
|
||||
#if !PORTABLE40
|
||||
#if !(PORTABLE || NET20 || NET35)
|
||||
#if !(PORTABLE || NET20 || NET35) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System;
|
||||
@@ -1635,7 +1635,7 @@ namespace Newtonsoft.Json.Converters
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.Integer)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
if (reader.Value is BigInteger)
|
||||
{
|
||||
return ((BigInteger)reader.Value).ToString(CultureInfo.InvariantCulture);
|
||||
@@ -1674,7 +1674,7 @@ namespace Newtonsoft.Json.Converters
|
||||
#if !PORTABLE
|
||||
return XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind));
|
||||
#else
|
||||
return XmlConvert.ToString(d);
|
||||
return XmlConvert.ToString(d, DateTimeUtils.ToDateTimeFormat(d.Kind));
|
||||
#endif
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.Null)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
#if !(NET20 || NET35 || PORTABLE40)
|
||||
@@ -238,7 +238,7 @@ namespace Newtonsoft.Json
|
||||
return value.ToString(null, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
private static string ToStringInternal(BigInteger value)
|
||||
{
|
||||
return value.ToString(null, CultureInfo.InvariantCulture);
|
||||
@@ -510,7 +510,7 @@ namespace Newtonsoft.Json
|
||||
return ToString((Uri)value);
|
||||
case PrimitiveTypeCode.TimeSpan:
|
||||
return ToString((TimeSpan)value);
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
case PrimitiveTypeCode.BigInteger:
|
||||
return ToStringInternal((BigInteger)value);
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Serialization;
|
||||
@@ -623,7 +623,7 @@ namespace Newtonsoft.Json
|
||||
if (!(Value is double))
|
||||
{
|
||||
double d;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (Value is BigInteger)
|
||||
{
|
||||
d = (double)(BigInteger)Value;
|
||||
@@ -683,7 +683,7 @@ namespace Newtonsoft.Json
|
||||
case JsonToken.Integer:
|
||||
case JsonToken.Float:
|
||||
bool b;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (Value is BigInteger)
|
||||
{
|
||||
b = (BigInteger)Value != 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Utilities;
|
||||
@@ -747,7 +747,7 @@ namespace Newtonsoft.Json
|
||||
case '9':
|
||||
ParseNumber(ReadType.Read);
|
||||
bool b;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (Value is BigInteger)
|
||||
{
|
||||
b = (BigInteger)Value != 0;
|
||||
@@ -2021,7 +2021,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
else if (parseResult == ParseResult.Overflow)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
string number = _stringReference.ToString();
|
||||
|
||||
if (number.Length > MaximumJavascriptIntegerCharacterLength)
|
||||
@@ -2076,7 +2076,7 @@ namespace Newtonsoft.Json
|
||||
SetToken(numberType, numberValue, false);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
// By using the BigInteger type in a separate method,
|
||||
// the runtime can execute the ParseNumber even if
|
||||
// the System.Numerics.BigInteger.Parse method is
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -359,7 +359,7 @@ namespace Newtonsoft.Json
|
||||
/// <param name="value">The <see cref="Object"/> value to write.</param>
|
||||
public override void WriteValue(object value)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
InternalWriteValue(JsonToken.Integer);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -840,7 +840,7 @@ namespace Newtonsoft.Json
|
||||
if (schema.DivisibleBy != null)
|
||||
{
|
||||
bool notDivisible;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
// not that this will lose any decimal point on DivisibleBy
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Utilities;
|
||||
@@ -532,7 +532,7 @@ namespace Newtonsoft.Json
|
||||
break;
|
||||
case JsonToken.Integer:
|
||||
ValidationUtils.ArgumentNotNull(value, nameof(value));
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
WriteValue((BigInteger)value);
|
||||
@@ -1392,7 +1392,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
// this is here because adding a WriteValue(BigInteger) to JsonWriter will
|
||||
// mean the user has to add a reference to System.Numerics.dll
|
||||
if (value is BigInteger)
|
||||
@@ -1550,7 +1550,7 @@ namespace Newtonsoft.Json
|
||||
case PrimitiveTypeCode.TimeSpanNullable:
|
||||
writer.WriteValue((value == null) ? (TimeSpan?)null : (TimeSpan)value);
|
||||
break;
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
case PrimitiveTypeCode.BigInteger:
|
||||
// this will call to WriteValue(object)
|
||||
writer.WriteValue((BigInteger)value);
|
||||
|
||||
@@ -706,10 +706,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
{
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
#if !(PORTABLE40 || PORTABLE || NET20)
|
||||
@@ -719,10 +716,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
protected virtual void OnPropertyChanging(string propertyName)
|
||||
{
|
||||
if (PropertyChanging != null)
|
||||
{
|
||||
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
|
||||
}
|
||||
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Dynamic;
|
||||
using System.Linq.Expressions;
|
||||
#endif
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Linq
|
||||
|
||||
private static readonly JTokenType[] BooleanTypes = new[] { JTokenType.Integer, JTokenType.Float, JTokenType.String, JTokenType.Comment, JTokenType.Raw, JTokenType.Boolean };
|
||||
private static readonly JTokenType[] NumberTypes = new[] { JTokenType.Integer, JTokenType.Float, JTokenType.String, JTokenType.Comment, JTokenType.Raw, JTokenType.Boolean };
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
private static readonly JTokenType[] BigIntegerTypes = new[] { JTokenType.Integer, JTokenType.Float, JTokenType.String, JTokenType.Comment, JTokenType.Raw, JTokenType.Boolean, JTokenType.Bytes };
|
||||
#endif
|
||||
private static readonly JTokenType[] StringTypes = new[] { JTokenType.Date, JTokenType.Integer, JTokenType.Float, JTokenType.String, JTokenType.Comment, JTokenType.Raw, JTokenType.Boolean, JTokenType.Bytes, JTokenType.Guid, JTokenType.TimeSpan, JTokenType.Uri };
|
||||
@@ -492,7 +492,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Boolean.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return Convert.ToBoolean((int)(BigInteger)v.Value);
|
||||
@@ -546,7 +546,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Boolean.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return Convert.ToBoolean((int)(BigInteger)v.Value);
|
||||
@@ -569,7 +569,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Int64.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (long)(BigInteger)v.Value;
|
||||
@@ -660,7 +660,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Decimal.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (decimal?)(BigInteger)v.Value;
|
||||
@@ -688,7 +688,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Double.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (double?)(BigInteger)v.Value;
|
||||
@@ -716,7 +716,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Char.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (char?)(BigInteger)v.Value;
|
||||
@@ -739,7 +739,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Int32.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (int)(BigInteger)v.Value;
|
||||
@@ -762,7 +762,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Int16.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (short)(BigInteger)v.Value;
|
||||
@@ -786,7 +786,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to UInt16.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (ushort)(BigInteger)v.Value;
|
||||
@@ -810,7 +810,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Char.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (char)(BigInteger)v.Value;
|
||||
@@ -833,7 +833,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Byte.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (byte)(BigInteger)v.Value;
|
||||
@@ -857,7 +857,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to SByte.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (sbyte)(BigInteger)v.Value;
|
||||
@@ -885,7 +885,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Int32.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (int?)(BigInteger)v.Value;
|
||||
@@ -913,7 +913,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Int16.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (short?)(BigInteger)v.Value;
|
||||
@@ -942,7 +942,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to UInt16.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (ushort?)(BigInteger)v.Value;
|
||||
@@ -970,7 +970,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Byte.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (byte?)(BigInteger)v.Value;
|
||||
@@ -999,7 +999,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to SByte.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (sbyte?)(BigInteger)v.Value;
|
||||
@@ -1050,7 +1050,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Int64.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (long?)(BigInteger)v.Value;
|
||||
@@ -1078,7 +1078,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Single.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (float?)(BigInteger)v.Value;
|
||||
@@ -1101,7 +1101,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Decimal.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (decimal)(BigInteger)v.Value;
|
||||
@@ -1130,7 +1130,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to UInt32.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (uint?)(BigInteger)v.Value;
|
||||
@@ -1159,7 +1159,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to UInt64.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (ulong?)(BigInteger)v.Value;
|
||||
@@ -1182,7 +1182,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Double.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (double)(BigInteger)v.Value;
|
||||
@@ -1205,7 +1205,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to Single.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (float)(BigInteger)v.Value;
|
||||
@@ -1241,7 +1241,7 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
return Convert.ToBase64String((byte[])v.Value);
|
||||
}
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return ((BigInteger)v.Value).ToString(CultureInfo.InvariantCulture);
|
||||
@@ -1265,7 +1265,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to UInt32.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (uint)(BigInteger)v.Value;
|
||||
@@ -1289,7 +1289,7 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new ArgumentException("Can not convert {0} to UInt64.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return (ulong)(BigInteger)v.Value;
|
||||
@@ -1321,7 +1321,7 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
return Convert.FromBase64String(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
|
||||
}
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (v.Value is BigInteger)
|
||||
{
|
||||
return ((BigInteger)v.Value).ToByteArray();
|
||||
@@ -1456,7 +1456,7 @@ namespace Newtonsoft.Json.Linq
|
||||
return (v.Value is Uri) ? (Uri)v.Value : new Uri(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
private static BigInteger ToBigInteger(JToken value)
|
||||
{
|
||||
JValue v = EnsureValue(value);
|
||||
@@ -2035,7 +2035,7 @@ namespace Newtonsoft.Json.Linq
|
||||
return (TimeSpan?)this;
|
||||
case PrimitiveTypeCode.TimeSpan:
|
||||
return (TimeSpan)this;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
case PrimitiveTypeCode.BigIntegerNullable:
|
||||
return ToBigIntegerNullable(this);
|
||||
case PrimitiveTypeCode.BigInteger:
|
||||
@@ -2305,7 +2305,7 @@ namespace Newtonsoft.Json.Linq
|
||||
JPath p = new JPath(path);
|
||||
|
||||
JToken token = null;
|
||||
foreach (JToken t in p.Evaluate(this, errorWhenNoMatch))
|
||||
foreach (JToken t in p.Evaluate(this, this, errorWhenNoMatch))
|
||||
{
|
||||
if (token != null)
|
||||
{
|
||||
@@ -2341,7 +2341,7 @@ namespace Newtonsoft.Json.Linq
|
||||
public IEnumerable<JToken> SelectTokens(string path, bool errorWhenNoMatch)
|
||||
{
|
||||
JPath p = new JPath(path);
|
||||
return p.Evaluate(this, errorWhenNoMatch);
|
||||
return p.Evaluate(this, this, errorWhenNoMatch);
|
||||
}
|
||||
|
||||
#if !(NET35 || NET20 || PORTABLE40)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Utilities;
|
||||
@@ -221,7 +221,7 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <param name="value">The <see cref="Object"/> value to write.</param>
|
||||
public override void WriteValue(object value)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
InternalWriteValue(JsonToken.Integer);
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Globalization;
|
||||
using System.Dynamic;
|
||||
using System.Linq.Expressions;
|
||||
#endif
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
|
||||
#endif
|
||||
@@ -219,7 +219,7 @@ namespace Newtonsoft.Json.Linq
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
private static int CompareBigInteger(BigInteger i1, object i2)
|
||||
{
|
||||
int result = i1.CompareTo(ConvertUtils.ToBigInteger(i2));
|
||||
@@ -264,7 +264,7 @@ namespace Newtonsoft.Json.Linq
|
||||
switch (valueType)
|
||||
{
|
||||
case JTokenType.Integer:
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (objA is BigInteger)
|
||||
{
|
||||
return CompareBigInteger((BigInteger)objA, objB);
|
||||
@@ -287,7 +287,7 @@ namespace Newtonsoft.Json.Linq
|
||||
return Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture));
|
||||
}
|
||||
case JTokenType.Float:
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (objA is BigInteger)
|
||||
{
|
||||
return CompareBigInteger((BigInteger)objA, objB);
|
||||
@@ -428,7 +428,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (objA is BigInteger || objB is BigInteger)
|
||||
{
|
||||
if (objA == null || objB == null)
|
||||
@@ -632,7 +632,7 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
return JTokenType.Integer;
|
||||
}
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
else if (value is BigInteger)
|
||||
{
|
||||
return JTokenType.Integer;
|
||||
@@ -768,7 +768,7 @@ namespace Newtonsoft.Json.Linq
|
||||
{
|
||||
writer.WriteValue((ulong)_value);
|
||||
}
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
else if (_value is BigInteger)
|
||||
{
|
||||
writer.WriteValue((BigInteger)_value);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public int? Index { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken t in current)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public List<int> Indexes { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken t in current)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
public int? End { get; set; }
|
||||
public int? Step { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
if (Step == 0)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken t in current)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public List<string> Names { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken t in current)
|
||||
{
|
||||
|
||||
@@ -429,15 +429,19 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
EatWhitespace();
|
||||
|
||||
if (_expression[_currentIndex] != '@')
|
||||
List<PathFilter> expressionPath = new List<PathFilter>();
|
||||
|
||||
if (_expression[_currentIndex] == '$')
|
||||
{
|
||||
expressionPath.Add(new RootFilter());
|
||||
}
|
||||
else if (_expression[_currentIndex] != '@')
|
||||
{
|
||||
throw new JsonException("Unexpected character while parsing path query: " + _expression[_currentIndex]);
|
||||
}
|
||||
|
||||
_currentIndex++;
|
||||
|
||||
List<PathFilter> expressionPath = new List<PathFilter>();
|
||||
|
||||
if (ParsePath(expressionPath, _currentIndex, true))
|
||||
{
|
||||
throw new JsonException("Path ended with open query.");
|
||||
@@ -758,17 +762,17 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
}
|
||||
}
|
||||
|
||||
internal IEnumerable<JToken> Evaluate(JToken t, bool errorWhenNoMatch)
|
||||
internal IEnumerable<JToken> Evaluate(JToken root, JToken t, bool errorWhenNoMatch)
|
||||
{
|
||||
return Evaluate(Filters, t, errorWhenNoMatch);
|
||||
return Evaluate(Filters, root, t, errorWhenNoMatch);
|
||||
}
|
||||
|
||||
internal static IEnumerable<JToken> Evaluate(List<PathFilter> filters, JToken t, bool errorWhenNoMatch)
|
||||
internal static IEnumerable<JToken> Evaluate(List<PathFilter> filters, JToken root, JToken t, bool errorWhenNoMatch)
|
||||
{
|
||||
IEnumerable<JToken> current = new[] { t };
|
||||
foreach (PathFilter filter in filters)
|
||||
{
|
||||
current = filter.ExecuteFilter(current, errorWhenNoMatch);
|
||||
current = filter.ExecuteFilter(root, current, errorWhenNoMatch);
|
||||
}
|
||||
|
||||
return current;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
internal abstract class PathFilter
|
||||
{
|
||||
public abstract IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch);
|
||||
public abstract IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch);
|
||||
|
||||
protected static JToken GetTokenIndex(JToken t, bool errorWhenNoMatch, int index)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public QueryOperator Operator { get; set; }
|
||||
|
||||
public abstract bool IsMatch(JToken t);
|
||||
public abstract bool IsMatch(JToken root, JToken t);
|
||||
}
|
||||
|
||||
internal class CompositeExpression : QueryExpression
|
||||
@@ -36,14 +36,14 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
Expressions = new List<QueryExpression>();
|
||||
}
|
||||
|
||||
public override bool IsMatch(JToken t)
|
||||
public override bool IsMatch(JToken root, JToken t)
|
||||
{
|
||||
switch (Operator)
|
||||
{
|
||||
case QueryOperator.And:
|
||||
foreach (QueryExpression e in Expressions)
|
||||
{
|
||||
if (!e.IsMatch(t))
|
||||
if (!e.IsMatch(root, t))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
case QueryOperator.Or:
|
||||
foreach (QueryExpression e in Expressions)
|
||||
{
|
||||
if (e.IsMatch(t))
|
||||
if (e.IsMatch(root, t))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -69,9 +69,9 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
public List<PathFilter> Path { get; set; }
|
||||
public JValue Value { get; set; }
|
||||
|
||||
public override bool IsMatch(JToken t)
|
||||
public override bool IsMatch(JToken root, JToken t)
|
||||
{
|
||||
IEnumerable<JToken> pathResult = JPath.Evaluate(Path, t, false);
|
||||
IEnumerable<JToken> pathResult = JPath.Evaluate(Path, root, t, false);
|
||||
|
||||
foreach (JToken r in pathResult)
|
||||
{
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public QueryExpression Expression { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken t in current)
|
||||
{
|
||||
foreach (JToken v in t)
|
||||
{
|
||||
if (Expression.IsMatch(v))
|
||||
if (Expression.IsMatch(root, v))
|
||||
{
|
||||
yield return v;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
internal class RootFilter : PathFilter
|
||||
{
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,17 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
public override IEnumerable<JToken> ExecuteFilter(JToken root, IEnumerable<JToken> current, bool errorWhenNoMatch)
|
||||
{
|
||||
foreach (JToken root in current)
|
||||
foreach (JToken c in current)
|
||||
{
|
||||
if (Name == null)
|
||||
{
|
||||
yield return root;
|
||||
yield return c;
|
||||
}
|
||||
|
||||
JToken value = root;
|
||||
JToken container = root;
|
||||
JToken value = c;
|
||||
JToken container = c;
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -26,12 +26,12 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
}
|
||||
else
|
||||
{
|
||||
while (value != null && value != root && value == value.Parent.Last)
|
||||
while (value != null && value != c && value == value.Parent.Last)
|
||||
{
|
||||
value = value.Parent;
|
||||
}
|
||||
|
||||
if (value == null || value == root)
|
||||
if (value == null || value == c)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\RootFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||
<Compile Include="Linq\MergeArrayHandling.cs" />
|
||||
<Compile Include="Linq\MergeNullValueHandling.cs" />
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\RootFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||
<Compile Include="Linq\MergeArrayHandling.cs" />
|
||||
<Compile Include="Linq\MergeNullValueHandling.cs" />
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\RootFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||
<Compile Include="Linq\MergeArrayHandling.cs" />
|
||||
<Compile Include="Linq\MergeNullValueHandling.cs" />
|
||||
|
||||
@@ -128,6 +128,7 @@
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\RootFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||
<Compile Include="Linq\JToken.cs" />
|
||||
<Compile Include="Linq\JTokenEqualityComparer.cs" />
|
||||
|
||||
@@ -133,6 +133,7 @@
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\RootFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||
<Compile Include="Linq\JToken.cs" />
|
||||
<Compile Include="Linq\JTokenEqualityComparer.cs" />
|
||||
|
||||
@@ -131,6 +131,7 @@
|
||||
<Compile Include="Linq\JsonPath\PathFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryExpression.cs" />
|
||||
<Compile Include="Linq\JsonPath\QueryFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\RootFilter.cs" />
|
||||
<Compile Include="Linq\JsonPath\ScanFilter.cs" />
|
||||
<Compile Include="Linq\JToken.cs" />
|
||||
<Compile Include="Linq\JTokenEqualityComparer.cs" />
|
||||
|
||||
@@ -32,8 +32,10 @@ using System.Security;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
#if NETSTANDARD10
|
||||
#if NETSTANDARD1_0
|
||||
[assembly: AssemblyTitle("Json.NET .NET Standard 1.0")]
|
||||
#elif NETSTANDARD1_1
|
||||
[assembly: AssemblyTitle("Json.NET .NET Standard 1.1")]
|
||||
#elif PORTABLE40
|
||||
[assembly: AssemblyTitle("Json.NET Portable .NET 4.0")]
|
||||
#elif PORTABLE
|
||||
|
||||
@@ -487,7 +487,7 @@ namespace Newtonsoft.Json.Schema
|
||||
case PrimitiveTypeCode.UInt32:
|
||||
case PrimitiveTypeCode.Int64:
|
||||
case PrimitiveTypeCode.UInt64:
|
||||
#if !(PORTABLE || NET35 || NET20)
|
||||
#if !(PORTABLE || NET35 || NET20) || NETSTANDARD1_1
|
||||
case PrimitiveTypeCode.BigInteger:
|
||||
#endif
|
||||
return schemaType | JsonSchemaType.Integer;
|
||||
|
||||
@@ -28,6 +28,7 @@ using System.Runtime.Serialization;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
@@ -38,9 +39,17 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
internal static readonly DefaultSerializationBinder Instance = new DefaultSerializationBinder();
|
||||
|
||||
private readonly ThreadSafeStore<TypeNameKey, Type> _typeCache = new ThreadSafeStore<TypeNameKey, Type>(GetTypeFromTypeNameKey);
|
||||
private readonly ThreadSafeStore<TypeNameKey, Type> _typeCache;
|
||||
|
||||
private static Type GetTypeFromTypeNameKey(TypeNameKey typeNameKey)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DefaultSerializationBinder"/> class.
|
||||
/// </summary>
|
||||
public DefaultSerializationBinder()
|
||||
{
|
||||
_typeCache = new ThreadSafeStore<TypeNameKey, Type>(GetTypeFromTypeNameKey);
|
||||
}
|
||||
|
||||
private Type GetTypeFromTypeNameKey(TypeNameKey typeNameKey)
|
||||
{
|
||||
string assemblyName = typeNameKey.AssemblyName;
|
||||
string typeName = typeNameKey.TypeName;
|
||||
@@ -68,7 +77,8 @@ namespace Newtonsoft.Json.Serialization
|
||||
Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (Assembly a in loadedAssemblies)
|
||||
{
|
||||
if (a.FullName == assemblyName)
|
||||
// check for both full name or partial name match
|
||||
if (a.FullName == assemblyName || a.GetName().Name == assemblyName)
|
||||
{
|
||||
assembly = a;
|
||||
break;
|
||||
@@ -85,7 +95,24 @@ namespace Newtonsoft.Json.Serialization
|
||||
Type type = assembly.GetType(typeName);
|
||||
if (type == null)
|
||||
{
|
||||
throw new JsonSerializationException("Could not find type '{0}' in assembly '{1}'.".FormatWith(CultureInfo.InvariantCulture, typeName, assembly.FullName));
|
||||
// if generic type, try manually parsing the type arguments for the case of dynamically loaded assemblies
|
||||
// example generic typeName format: System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
|
||||
if (typeName.IndexOf('`') >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
type = GetGenericTypeFromTypeName(typeName, assembly);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JsonSerializationException("Could not find type '{0}' in assembly '{1}'.".FormatWith(CultureInfo.InvariantCulture, typeName, assembly.FullName), ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new JsonSerializationException("Could not find type '{0}' in assembly '{1}'.".FormatWith(CultureInfo.InvariantCulture, typeName, assembly.FullName));
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
@@ -96,37 +123,55 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
internal struct TypeNameKey : IEquatable<TypeNameKey>
|
||||
private Type GetGenericTypeFromTypeName(string typeName, Assembly assembly)
|
||||
{
|
||||
internal readonly string AssemblyName;
|
||||
internal readonly string TypeName;
|
||||
|
||||
public TypeNameKey(string assemblyName, string typeName)
|
||||
Type type = null;
|
||||
int openBracketIndex = typeName.IndexOf('[');
|
||||
if (openBracketIndex >= 0)
|
||||
{
|
||||
AssemblyName = assemblyName;
|
||||
TypeName = typeName;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((AssemblyName != null) ? AssemblyName.GetHashCode() : 0)
|
||||
^ ((TypeName != null) ? TypeName.GetHashCode() : 0);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is TypeNameKey))
|
||||
string genericTypeDefName = typeName.Substring(0, openBracketIndex);
|
||||
Type genericTypeDef = assembly.GetType(genericTypeDefName);
|
||||
if (genericTypeDef != null)
|
||||
{
|
||||
return false;
|
||||
List<Type> genericTypeArguments = new List<Type>();
|
||||
int scope = 0;
|
||||
int typeArgStartIndex = 0;
|
||||
int endIndex = typeName.Length - 1;
|
||||
for (int i = openBracketIndex + 1; i < endIndex; ++i)
|
||||
{
|
||||
char current = typeName[i];
|
||||
switch (current)
|
||||
{
|
||||
case '[':
|
||||
if (scope == 0)
|
||||
{
|
||||
typeArgStartIndex = i + 1;
|
||||
}
|
||||
++scope;
|
||||
break;
|
||||
case ']':
|
||||
--scope;
|
||||
if (scope == 0)
|
||||
{
|
||||
string typeArgAssemblyQualifiedName = typeName.Substring(typeArgStartIndex, i - typeArgStartIndex);
|
||||
|
||||
TypeNameKey typeNameKey = ReflectionUtils.SplitFullyQualifiedTypeName(typeArgAssemblyQualifiedName);
|
||||
genericTypeArguments.Add(GetTypeByName(typeNameKey));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
type = genericTypeDef.MakeGenericType(genericTypeArguments.ToArray());
|
||||
}
|
||||
|
||||
return Equals((TypeNameKey)obj);
|
||||
}
|
||||
|
||||
public bool Equals(TypeNameKey other)
|
||||
{
|
||||
return (AssemblyName == other.AssemblyName && TypeName == other.TypeName);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private Type GetTypeByName(TypeNameKey typeNameKey)
|
||||
{
|
||||
return _typeCache.Get(typeNameKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,7 +184,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// </returns>
|
||||
public override Type BindToType(string assemblyName, string typeName)
|
||||
{
|
||||
return _typeCache.Get(new TypeNameKey(assemblyName, typeName));
|
||||
return GetTypeByName(new TypeNameKey(assemblyName, typeName));
|
||||
}
|
||||
|
||||
#if !(NET35 || NET20)
|
||||
|
||||
@@ -33,7 +33,7 @@ using System.Dynamic;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Reflection;
|
||||
@@ -778,14 +778,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
if (resolvedTypeNameHandling != TypeNameHandling.None)
|
||||
{
|
||||
string typeName;
|
||||
string assemblyName;
|
||||
ReflectionUtils.SplitFullyQualifiedTypeName(qualifiedTypeName, out typeName, out assemblyName);
|
||||
TypeNameKey typeNameKey = ReflectionUtils.SplitFullyQualifiedTypeName(qualifiedTypeName);
|
||||
|
||||
Type specifiedType;
|
||||
try
|
||||
{
|
||||
specifiedType = Serializer._binder.BindToType(assemblyName, typeName);
|
||||
specifiedType = Serializer._binder.BindToType(typeNameKey.AssemblyName, typeNameKey.TypeName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -968,7 +966,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
return ConvertUtils.FromBigInteger((BigInteger)value, contract.NonNullableUnderlyingType);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -139,7 +139,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
public override void WriteValue(object value)
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
if (value is BigInteger)
|
||||
{
|
||||
_textWriter.WriteValue(value);
|
||||
|
||||
@@ -61,6 +61,9 @@ namespace Newtonsoft.Json
|
||||
|
||||
/// <summary>
|
||||
/// Include the .NET type name when the type of the object being serialized is not the same as its declared type.
|
||||
/// Note that this doesn't include the root serialized object by default. To include the root object's type name in JSON
|
||||
/// you must specify a root type object with <see cref="Newtonsoft.Json.JsonConvert.SerializeObject(object, Type, Newtonsoft.Json.JsonSerializerSettings)"/>
|
||||
/// or <see cref="Newtonsoft.Json.JsonSerializer.Serialize(Newtonsoft.Json.JsonWriter, object, Type)" />.
|
||||
/// </summary>
|
||||
Auto = 4
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -145,7 +145,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
{ typeof(Guid?), PrimitiveTypeCode.GuidNullable },
|
||||
{ typeof(TimeSpan), PrimitiveTypeCode.TimeSpan },
|
||||
{ typeof(TimeSpan?), PrimitiveTypeCode.TimeSpanNullable },
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
{ typeof(BigInteger), PrimitiveTypeCode.BigInteger },
|
||||
{ typeof(BigInteger?), PrimitiveTypeCode.BigIntegerNullable },
|
||||
#endif
|
||||
@@ -311,7 +311,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
return o => call(null, o);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
internal static BigInteger ToBigInteger(object value)
|
||||
{
|
||||
if (value is BigInteger)
|
||||
@@ -540,7 +540,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
if (targetType == typeof(BigInteger))
|
||||
{
|
||||
value = ToBigInteger(initialValue);
|
||||
|
||||
@@ -73,6 +73,21 @@ namespace Newtonsoft.Json.Utilities
|
||||
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("kind", kind, "Unexpected DateTimeKind value.");
|
||||
}
|
||||
}
|
||||
#else
|
||||
public static string ToDateTimeFormat(DateTimeKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case DateTimeKind.Local:
|
||||
return "yyyy-MM-ddTHH:mm:sszzzzzzz";
|
||||
case DateTimeKind.Unspecified:
|
||||
return "s";
|
||||
case DateTimeKind.Utc:
|
||||
return "yyyy-MM-ddTHH:mm:ssZ";
|
||||
default:
|
||||
throw new Exception("Unexpected DateTimeKind value.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static DateTime EnsureDateTime(DateTime value, DateTimeZoneHandling timeZone)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Reflection;
|
||||
@@ -858,10 +858,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void SplitFullyQualifiedTypeName(string fullyQualifiedTypeName, out string typeName, out string assemblyName)
|
||||
public static TypeNameKey SplitFullyQualifiedTypeName(string fullyQualifiedTypeName)
|
||||
{
|
||||
int? assemblyDelimiterIndex = GetAssemblyDelimiterIndex(fullyQualifiedTypeName);
|
||||
|
||||
string typeName;
|
||||
string assemblyName;
|
||||
|
||||
if (assemblyDelimiterIndex != null)
|
||||
{
|
||||
typeName = fullyQualifiedTypeName.Substring(0, assemblyDelimiterIndex.GetValueOrDefault()).Trim();
|
||||
@@ -872,6 +875,8 @@ namespace Newtonsoft.Json.Utilities
|
||||
typeName = fullyQualifiedTypeName;
|
||||
assemblyName = null;
|
||||
}
|
||||
|
||||
return new TypeNameKey(assemblyName, typeName);
|
||||
}
|
||||
|
||||
private static int? GetAssemblyDelimiterIndex(string fullyQualifiedTypeName)
|
||||
@@ -1100,7 +1105,7 @@ namespace Newtonsoft.Json.Utilities
|
||||
return 0m;
|
||||
case PrimitiveTypeCode.DateTime:
|
||||
return new DateTime();
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
case PrimitiveTypeCode.BigInteger:
|
||||
return new BigInteger();
|
||||
#endif
|
||||
@@ -1121,4 +1126,36 @@ namespace Newtonsoft.Json.Utilities
|
||||
return Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
|
||||
internal struct TypeNameKey : IEquatable<TypeNameKey>
|
||||
{
|
||||
internal readonly string AssemblyName;
|
||||
internal readonly string TypeName;
|
||||
|
||||
public TypeNameKey(string assemblyName, string typeName)
|
||||
{
|
||||
AssemblyName = assemblyName;
|
||||
TypeName = typeName;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (AssemblyName?.GetHashCode() ?? 0) ^ (TypeName?.GetHashCode() ?? 0);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is TypeNameKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Equals((TypeNameKey)obj);
|
||||
}
|
||||
|
||||
public bool Equals(TypeNameKey other)
|
||||
{
|
||||
return (AssemblyName == other.AssemblyName && TypeName == other.TypeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@
|
||||
"netstandard1.0": {
|
||||
"buildOptions": {
|
||||
"define": [
|
||||
"NETSTANDARD10",
|
||||
"NETSTANDARD1_0",
|
||||
"PORTABLE"
|
||||
]
|
||||
},
|
||||
@@ -129,6 +129,39 @@
|
||||
"System.Xml.ReaderWriter": "4.0.11",
|
||||
"System.Xml.XDocument": "4.0.11"
|
||||
}
|
||||
},
|
||||
"netstandard1.1": {
|
||||
"buildOptions": {
|
||||
"define": [
|
||||
"NETSTANDARD1_1",
|
||||
"PORTABLE"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.0.1",
|
||||
"System.Collections": "4.0.11",
|
||||
"System.Diagnostics.Debug": "4.0.11",
|
||||
"System.Dynamic.Runtime": "4.0.11",
|
||||
"System.Globalization": "4.0.11",
|
||||
"System.IO": "4.1.0",
|
||||
"System.Linq": "4.1.0",
|
||||
"System.Linq.Expressions": "4.1.0",
|
||||
"System.ObjectModel": "4.0.12",
|
||||
"System.Reflection": "4.1.0",
|
||||
"System.Reflection.Extensions": "4.0.1",
|
||||
"System.Resources.ResourceManager": "4.0.1",
|
||||
"System.Runtime": "4.1.0",
|
||||
"System.Runtime.Extensions": "4.1.0",
|
||||
"System.Runtime.Numerics": "4.0.1",
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"System.Text.Encoding": "4.0.11",
|
||||
"System.Text.Encoding.Extensions": "4.0.11",
|
||||
"System.Text.RegularExpressions": "4.1.0",
|
||||
"System.Threading": "4.0.11",
|
||||
"System.Threading.Tasks": "4.0.11",
|
||||
"System.Xml.ReaderWriter": "4.0.11",
|
||||
"System.Xml.XDocument": "4.0.11"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user