diff --git a/Src/Newtonsoft.Json/Linq/CommentHandling.cs b/Src/Newtonsoft.Json/Linq/CommentHandling.cs
index ac179dd3..579235c5 100644
--- a/Src/Newtonsoft.Json/Linq/CommentHandling.cs
+++ b/Src/Newtonsoft.Json/Linq/CommentHandling.cs
@@ -40,20 +40,4 @@ namespace Newtonsoft.Json.Linq
///
Load = 1
}
-
- ///
- /// Specifies how line information is handled when loading JSON.
- ///
- public enum LineInfoHandling
- {
- ///
- /// Ignore line information.
- ///
- Ignore = 0,
-
- ///
- /// Load line information.
- ///
- Load = 1
- }
}
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Linq/Extensions.cs b/Src/Newtonsoft.Json/Linq/Extensions.cs
index 68295fdc..13fbce03 100644
--- a/Src/Newtonsoft.Json/Linq/Extensions.cs
+++ b/Src/Newtonsoft.Json/Linq/Extensions.cs
@@ -171,8 +171,7 @@ namespace Newtonsoft.Json.Linq
{
ValidationUtils.ArgumentNotNull(value, nameof(value));
- JToken token = value as JToken;
- if (token == null)
+ if (!(value is JToken token))
{
throw new ArgumentException("Source value must be a JToken.");
}
@@ -275,9 +274,9 @@ namespace Newtonsoft.Json.Linq
throw new InvalidCastException("Cannot cast {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, token.GetType(), typeof(T)));
}
- if (value.Value is U)
+ if (value.Value is U u)
{
- return (U)value.Value;
+ return u;
}
Type targetType = typeof(U);
diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs
index 90f25c8d..270027e8 100644
--- a/Src/Newtonsoft.Json/Linq/JArray.cs
+++ b/Src/Newtonsoft.Json/Linq/JArray.cs
@@ -90,8 +90,7 @@ namespace Newtonsoft.Json.Linq
internal override bool DeepEquals(JToken node)
{
- JArray t = node as JArray;
- return (t != null && ContentsEqual(t));
+ return (node is JArray t && ContentsEqual(t));
}
internal override JToken CloneToken()
diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs
index 966bc5b0..03b3f550 100644
--- a/Src/Newtonsoft.Json/Linq/JConstructor.cs
+++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs
@@ -52,8 +52,7 @@ namespace Newtonsoft.Json.Linq
internal override void MergeItem(object content, JsonMergeSettings settings)
{
- JConstructor c = content as JConstructor;
- if (c == null)
+ if (!(content is JConstructor c))
{
return;
}
@@ -140,8 +139,7 @@ namespace Newtonsoft.Json.Linq
internal override bool DeepEquals(JToken node)
{
- JConstructor c = node as JConstructor;
- return (c != null && _name == c.Name && ContentsEqual(c));
+ return (node is JConstructor c && _name == c.Name && ContentsEqual(c));
}
internal override JToken CloneToken()
diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs
index 0d54b89d..dff7f4ba 100644
--- a/Src/Newtonsoft.Json/Linq/JContainer.cs
+++ b/Src/Newtonsoft.Json/Linq/JContainer.cs
@@ -304,8 +304,7 @@ namespace Newtonsoft.Json.Linq
foreach (JToken o in ChildrenTokens)
{
yield return o;
- JContainer c = o as JContainer;
- if (c != null)
+ if (o is JContainer c)
{
foreach (JToken d in c.Descendants())
{
@@ -597,8 +596,7 @@ namespace Newtonsoft.Json.Linq
internal static bool IsTokenUnchanged(JToken currentValue, JToken newValue)
{
- JValue v1 = currentValue as JValue;
- if (v1 != null)
+ if (currentValue is JValue v1)
{
// null will get turned into a JValue of type null
if (v1.Type == JTokenType.Null && newValue == null)
@@ -668,8 +666,7 @@ namespace Newtonsoft.Json.Linq
internal static JToken CreateFromContent(object content)
{
- JToken token = content as JToken;
- if (token != null)
+ if (content is JToken token)
{
return token;
}
@@ -944,8 +941,7 @@ namespace Newtonsoft.Json.Linq
return null;
}
- JToken token = value as JToken;
- if (token != null)
+ if (value is JToken token)
{
return token;
}
@@ -1148,8 +1144,7 @@ namespace Newtonsoft.Json.Linq
{
JToken sourceItem = target[i];
- JContainer existingContainer = sourceItem as JContainer;
- if (existingContainer != null)
+ if (sourceItem is JContainer existingContainer)
{
existingContainer.Merge(targetItem, settings);
}
diff --git a/Src/Newtonsoft.Json/Linq/JEnumerable.cs b/Src/Newtonsoft.Json/Linq/JEnumerable.cs
index 095010fa..fd6729a7 100644
--- a/Src/Newtonsoft.Json/Linq/JEnumerable.cs
+++ b/Src/Newtonsoft.Json/Linq/JEnumerable.cs
@@ -113,9 +113,9 @@ namespace Newtonsoft.Json.Linq
///
public override bool Equals(object obj)
{
- if (obj is JEnumerable)
+ if (obj is JEnumerable enumerable)
{
- return Equals((JEnumerable)obj);
+ return Equals(enumerable);
}
return false;
diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs
index 551a39eb..5d9081f9 100644
--- a/Src/Newtonsoft.Json/Linq/JObject.cs
+++ b/Src/Newtonsoft.Json/Linq/JObject.cs
@@ -115,8 +115,7 @@ namespace Newtonsoft.Json.Linq
internal override bool DeepEquals(JToken node)
{
- JObject t = node as JObject;
- if (t == null)
+ if (!(node is JObject t))
{
return false;
}
@@ -169,8 +168,7 @@ namespace Newtonsoft.Json.Linq
internal override void MergeItem(object content, JsonMergeSettings settings)
{
- JObject o = content as JObject;
- if (o == null)
+ if (!(content is JObject o))
{
return;
}
@@ -185,8 +183,7 @@ namespace Newtonsoft.Json.Linq
}
else if (contentItem.Value != null)
{
- JContainer existingContainer = existingProperty.Value as JContainer;
- if (existingContainer == null || existingContainer.Type != contentItem.Value.Type)
+ if (!(existingProperty.Value is JContainer existingContainer) || existingContainer.Type != contentItem.Value.Type)
{
if (contentItem.Value.Type != JTokenType.Null || settings?.MergeNullValueHandling == MergeNullValueHandling.Merge)
{
@@ -257,8 +254,7 @@ namespace Newtonsoft.Json.Linq
return null;
}
- JToken property;
- _properties.TryGetValue(name, out property);
+ _properties.TryGetValue(name, out JToken property);
return (JProperty)property;
}
@@ -281,8 +277,7 @@ namespace Newtonsoft.Json.Linq
{
ValidationUtils.ArgumentNotNull(key, nameof(key));
- string propertyName = key as string;
- if (propertyName == null)
+ if (!(key is string propertyName))
{
throw new ArgumentException("Accessed JObject values with invalid key value: {0}. Object property name expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key)));
}
@@ -293,8 +288,7 @@ namespace Newtonsoft.Json.Linq
{
ValidationUtils.ArgumentNotNull(key, nameof(key));
- string propertyName = key as string;
- if (propertyName == null)
+ if (!(key is string propertyName))
{
throw new ArgumentException("Set JObject values with invalid key value: {0}. Object property name expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key)));
}
@@ -794,10 +788,8 @@ namespace Newtonsoft.Json.Linq
public override bool TrySetMember(JObject instance, SetMemberBinder binder, object value)
{
- JToken v = value as JToken;
-
// this can throw an error if value isn't a valid for a JValue
- if (v == null)
+ if (!(value is JToken v))
{
v = new JValue(value);
}
diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs
index 0fab7be3..ab938a9b 100644
--- a/Src/Newtonsoft.Json/Linq/JProperty.cs
+++ b/Src/Newtonsoft.Json/Linq/JProperty.cs
@@ -263,8 +263,7 @@ namespace Newtonsoft.Json.Linq
internal override bool DeepEquals(JToken node)
{
- JProperty t = node as JProperty;
- return (t != null && _name == t.Name && ContentsEqual(t));
+ return (node is JProperty t && _name == t.Name && ContentsEqual(t));
}
internal override JToken CloneToken()
@@ -338,7 +337,7 @@ namespace Newtonsoft.Json.Linq
internal override int GetDeepHashCode()
{
- return _name.GetHashCode() ^ ((Value != null) ? Value.GetDeepHashCode() : 0);
+ return _name.GetHashCode() ^ (Value?.GetDeepHashCode() ?? 0);
}
///
diff --git a/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs b/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs
index 6477ccf5..b80f696d 100644
--- a/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs
+++ b/Src/Newtonsoft.Json/Linq/JPropertyKeyedCollection.cs
@@ -98,8 +98,7 @@ namespace Newtonsoft.Json.Linq
}
string key = GetKeyForItem(item);
- JToken value;
- return _dictionary.TryGetValue(key, out value);
+ return _dictionary.TryGetValue(key, out _);
}
private void EnsureDictionary()
@@ -258,8 +257,7 @@ namespace Newtonsoft.Json.Linq
foreach (KeyValuePair keyAndProperty in d1)
{
- JToken secondValue;
- if (!d2.TryGetValue(keyAndProperty.Key, out secondValue))
+ if (!d2.TryGetValue(keyAndProperty.Key, out JToken secondValue))
{
return false;
}
diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs
index 07352836..0ba60d6e 100644
--- a/Src/Newtonsoft.Json/Linq/JToken.cs
+++ b/Src/Newtonsoft.Json/Linq/JToken.cs
@@ -34,7 +34,6 @@ using System.IO;
#if HAVE_BIG_INTEGER
using System.Numerics;
#endif
-using System.Text;
using Newtonsoft.Json.Utilities;
using System.Diagnostics;
using System.Globalization;
@@ -449,9 +448,9 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentNullException(nameof(value));
}
- if (value is JProperty)
+ if (value is JProperty property)
{
- value = ((JProperty)value).Value;
+ value = property.Value;
}
JValue v = value as JValue;
@@ -491,9 +490,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return Convert.ToBoolean((int)(BigInteger)v.Value);
+ return Convert.ToBoolean((int)integer);
}
#endif
@@ -514,16 +513,16 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentException("Can not convert {0} to DateTimeOffset.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
}
- if (v.Value is DateTimeOffset)
+ if (v.Value is DateTimeOffset offset)
{
- return (DateTimeOffset)v.Value;
+ return offset;
}
- string s = v.Value as string;
- if (s != null)
+ if (v.Value is string s)
{
return DateTimeOffset.Parse(s, CultureInfo.InvariantCulture);
}
+
return new DateTimeOffset(Convert.ToDateTime(v.Value, CultureInfo.InvariantCulture));
}
#endif
@@ -547,9 +546,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return Convert.ToBoolean((int)(BigInteger)v.Value);
+ return Convert.ToBoolean((int)integer);
}
#endif
@@ -570,9 +569,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (long)(BigInteger)v.Value;
+ return (long)integer;
}
#endif
@@ -598,9 +597,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_DATE_TIME_OFFSET
- if (v.Value is DateTimeOffset)
+ if (v.Value is DateTimeOffset offset)
{
- return ((DateTimeOffset)v.Value).DateTime;
+ return offset.DateTime;
}
#endif
@@ -630,13 +629,12 @@ namespace Newtonsoft.Json.Linq
{
return null;
}
- if (v.Value is DateTimeOffset)
+ if (v.Value is DateTimeOffset offset)
{
- return (DateTimeOffset?)v.Value;
+ return offset;
}
- string s = v.Value as string;
- if (s != null)
+ if (v.Value is string s)
{
return DateTimeOffset.Parse(s, CultureInfo.InvariantCulture);
}
@@ -664,9 +662,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (decimal?)(BigInteger)v.Value;
+ return (decimal?)integer;
}
#endif
@@ -692,9 +690,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (double?)(BigInteger)v.Value;
+ return (double?)integer;
}
#endif
@@ -720,9 +718,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (char?)(BigInteger)v.Value;
+ return (char?)integer;
}
#endif
@@ -743,9 +741,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (int)(BigInteger)v.Value;
+ return (int)integer;
}
#endif
@@ -766,9 +764,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (short)(BigInteger)v.Value;
+ return (short)integer;
}
#endif
@@ -790,9 +788,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (ushort)(BigInteger)v.Value;
+ return (ushort)integer;
}
#endif
@@ -814,9 +812,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (char)(BigInteger)v.Value;
+ return (char)integer;
}
#endif
@@ -837,9 +835,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (byte)(BigInteger)v.Value;
+ return (byte)integer;
}
#endif
@@ -861,9 +859,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (sbyte)(BigInteger)v.Value;
+ return (sbyte)integer;
}
#endif
@@ -889,9 +887,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (int?)(BigInteger)v.Value;
+ return (int?)integer;
}
#endif
@@ -917,9 +915,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (short?)(BigInteger)v.Value;
+ return (short?)integer;
}
#endif
@@ -946,9 +944,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (ushort?)(BigInteger)v.Value;
+ return (ushort?)integer;
}
#endif
@@ -974,9 +972,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (byte?)(BigInteger)v.Value;
+ return (byte?)integer;
}
#endif
@@ -1003,9 +1001,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (sbyte?)(BigInteger)v.Value;
+ return (sbyte?)integer;
}
#endif
@@ -1026,9 +1024,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_DATE_TIME_OFFSET
- if (v.Value is DateTimeOffset)
+ if (v.Value is DateTimeOffset offset)
{
- return ((DateTimeOffset)v.Value).DateTime;
+ return offset.DateTime;
}
#endif
@@ -1054,9 +1052,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (long?)(BigInteger)v.Value;
+ return (long?)integer;
}
#endif
@@ -1082,9 +1080,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (float?)(BigInteger)v.Value;
+ return (float?)integer;
}
#endif
@@ -1105,9 +1103,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (decimal)(BigInteger)v.Value;
+ return (decimal)integer;
}
#endif
@@ -1134,9 +1132,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (uint?)(BigInteger)v.Value;
+ return (uint?)integer;
}
#endif
@@ -1163,9 +1161,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (ulong?)(BigInteger)v.Value;
+ return (ulong?)integer;
}
#endif
@@ -1186,9 +1184,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (double)(BigInteger)v.Value;
+ return (double)integer;
}
#endif
@@ -1209,9 +1207,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (float)(BigInteger)v.Value;
+ return (float)integer;
}
#endif
@@ -1241,16 +1239,15 @@ namespace Newtonsoft.Json.Linq
return null;
}
- byte[] bytes = v.Value as byte[];
- if (bytes != null)
+ if (v.Value is byte[] bytes)
{
return Convert.ToBase64String(bytes);
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return ((BigInteger)v.Value).ToString(CultureInfo.InvariantCulture);
+ return integer.ToString(CultureInfo.InvariantCulture);
}
#endif
@@ -1272,9 +1269,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (uint)(BigInteger)v.Value;
+ return (uint)integer;
}
#endif
@@ -1296,9 +1293,9 @@ namespace Newtonsoft.Json.Linq
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return (ulong)(BigInteger)v.Value;
+ return (ulong)integer;
}
#endif
@@ -1328,14 +1325,13 @@ namespace Newtonsoft.Json.Linq
return Convert.FromBase64String(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
}
#if HAVE_BIG_INTEGER
- if (v.Value is BigInteger)
+ if (v.Value is BigInteger integer)
{
- return ((BigInteger)v.Value).ToByteArray();
+ return integer.ToByteArray();
}
#endif
- byte[] bytes = v.Value as byte[];
- if (bytes != null)
+ if (v.Value is byte[] bytes)
{
return bytes;
}
@@ -1356,13 +1352,12 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentException("Can not convert {0} to Guid.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
}
- byte[] bytes = v.Value as byte[];
- if (bytes != null)
+ if (v.Value is byte[] bytes)
{
return new Guid(bytes);
}
- return (v.Value is Guid) ? (Guid)v.Value : new Guid(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
+ return (v.Value is Guid guid) ? guid : new Guid(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
}
///
@@ -1388,13 +1383,12 @@ namespace Newtonsoft.Json.Linq
return null;
}
- byte[] bytes = v.Value as byte[];
- if (bytes != null)
+ if (v.Value is byte[] bytes)
{
return new Guid(bytes);
}
- return (v.Value is Guid) ? (Guid)v.Value : new Guid(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
+ return (v.Value is Guid guid) ? guid : new Guid(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
}
///
@@ -1410,7 +1404,7 @@ namespace Newtonsoft.Json.Linq
throw new ArgumentException("Can not convert {0} to TimeSpan.".FormatWith(CultureInfo.InvariantCulture, GetType(value)));
}
- return (v.Value is TimeSpan) ? (TimeSpan)v.Value : ConvertUtils.ParseTimeSpan(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
+ return (v.Value is TimeSpan span) ? span : ConvertUtils.ParseTimeSpan(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
}
///
@@ -1436,7 +1430,7 @@ namespace Newtonsoft.Json.Linq
return null;
}
- return (v.Value is TimeSpan) ? (TimeSpan)v.Value : ConvertUtils.ParseTimeSpan(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
+ return (v.Value is TimeSpan span) ? span : ConvertUtils.ParseTimeSpan(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
}
///
@@ -1462,7 +1456,7 @@ namespace Newtonsoft.Json.Linq
return null;
}
- return (v.Value is Uri) ? (Uri)v.Value : new Uri(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
+ return (v.Value is Uri uri) ? uri : new Uri(Convert.ToString(v.Value, CultureInfo.InvariantCulture));
}
#if HAVE_BIG_INTEGER
@@ -1939,8 +1933,7 @@ namespace Newtonsoft.Json.Linq
{
if (JsonConvert.DefaultSettings == null)
{
- bool isEnum;
- PrimitiveTypeCode typeCode = ConvertUtils.GetTypeCode(objectType, out isEnum);
+ PrimitiveTypeCode typeCode = ConvertUtils.GetTypeCode(objectType, out bool isEnum);
if (isEnum)
{
@@ -2419,8 +2412,7 @@ namespace Newtonsoft.Json.Linq
}
else
{
- object[] annotations = _annotations as object[];
- if (annotations == null)
+ if (!(_annotations is object[] annotations))
{
_annotations = new[] { _annotations, annotation };
}
@@ -2450,8 +2442,7 @@ namespace Newtonsoft.Json.Linq
{
if (_annotations != null)
{
- object[] annotations = _annotations as object[];
- if (annotations == null)
+ if (!(_annotations is object[] annotations))
{
return (_annotations as T);
}
@@ -2463,8 +2454,7 @@ namespace Newtonsoft.Json.Linq
break;
}
- T local = annotation as T;
- if (local != null)
+ if (annotation is T local)
{
return local;
}
@@ -2488,8 +2478,7 @@ namespace Newtonsoft.Json.Linq
if (_annotations != null)
{
- object[] annotations = _annotations as object[];
- if (annotations == null)
+ if (!(_annotations is object[] annotations))
{
if (type.IsInstanceOfType(_annotations))
{
@@ -2529,8 +2518,7 @@ namespace Newtonsoft.Json.Linq
yield break;
}
- object[] annotations = _annotations as object[];
- if (annotations != null)
+ if (_annotations is object[] annotations)
{
for (int i = 0; i < annotations.Length; i++)
{
@@ -2540,8 +2528,7 @@ namespace Newtonsoft.Json.Linq
break;
}
- T casted = o as T;
- if (casted != null)
+ if (o is T casted)
{
yield return casted;
}
@@ -2549,8 +2536,7 @@ namespace Newtonsoft.Json.Linq
yield break;
}
- T annotation = _annotations as T;
- if (annotation == null)
+ if (!(_annotations is T annotation))
{
yield break;
}
@@ -2575,8 +2561,7 @@ namespace Newtonsoft.Json.Linq
yield break;
}
- object[] annotations = _annotations as object[];
- if (annotations != null)
+ if (_annotations is object[] annotations)
{
for (int i = 0; i < annotations.Length; i++)
{
@@ -2610,8 +2595,7 @@ namespace Newtonsoft.Json.Linq
{
if (_annotations != null)
{
- object[] annotations = _annotations as object[];
- if (annotations == null)
+ if (!(_annotations is object[] annotations))
{
if (_annotations is T)
{
@@ -2666,8 +2650,7 @@ namespace Newtonsoft.Json.Linq
if (_annotations != null)
{
- object[] annotations = _annotations as object[];
- if (annotations == null)
+ if (!(_annotations is object[] annotations))
{
if (type.IsInstanceOfType(_annotations))
{
diff --git a/Src/Newtonsoft.Json/Linq/JTokenReader.cs b/Src/Newtonsoft.Json/Linq/JTokenReader.cs
index 16fba21e..a0a30eb0 100644
--- a/Src/Newtonsoft.Json/Linq/JTokenReader.cs
+++ b/Src/Newtonsoft.Json/Linq/JTokenReader.cs
@@ -76,8 +76,7 @@ namespace Newtonsoft.Json.Linq
return false;
}
- JContainer container = _current as JContainer;
- if (container != null && _parent != container)
+ if (_current is JContainer container && _parent != container)
{
return ReadInto(container);
}
diff --git a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs
index 03f1d6b1..3c823017 100644
--- a/Src/Newtonsoft.Json/Linq/JTokenWriter.cs
+++ b/Src/Newtonsoft.Json/Linq/JTokenWriter.cs
@@ -379,7 +379,7 @@ namespace Newtonsoft.Json.Linq
public override void WriteValue(char value)
{
base.WriteValue(value);
- string s = null;
+ string s;
#if HAVE_CHAR_TO_STRING_WITH_CULTURE
s = value.ToString(CultureInfo.InvariantCulture);
#else
@@ -485,10 +485,8 @@ namespace Newtonsoft.Json.Linq
internal override void WriteToken(JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments)
{
- JTokenReader tokenReader = reader as JTokenReader;
-
// cloning the token rather than reading then writing it doesn't lose some type information, e.g. Guid, byte[], etc
- if (tokenReader != null && writeChildren && writeDateConstructorAsDate && writeComments)
+ if (reader is JTokenReader tokenReader && writeChildren && writeDateConstructorAsDate && writeComments)
{
if (tokenReader.TokenType == JsonToken.None)
{
diff --git a/Src/Newtonsoft.Json/Linq/JValue.Async.cs b/Src/Newtonsoft.Json/Linq/JValue.Async.cs
index b4bb5366..91402d10 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.Async.cs
@@ -69,43 +69,43 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Undefined:
return writer.WriteUndefinedAsync(cancellationToken);
case JTokenType.Integer:
- if (_value is int)
+ if (_value is int i)
{
- return writer.WriteValueAsync((int)_value, cancellationToken);
+ return writer.WriteValueAsync(i, cancellationToken);
}
- if (_value is long)
+ if (_value is long l)
{
- return writer.WriteValueAsync((long)_value, cancellationToken);
+ return writer.WriteValueAsync(l, cancellationToken);
}
- if (_value is ulong)
+ if (_value is ulong ul)
{
- return writer.WriteValueAsync((ulong)_value, cancellationToken);
+ return writer.WriteValueAsync(ul, cancellationToken);
}
#if HAVE_BIG_INTEGER
- if (_value is BigInteger)
+ if (_value is BigInteger integer)
{
- return writer.WriteValueAsync((BigInteger)_value, cancellationToken);
+ return writer.WriteValueAsync(integer, cancellationToken);
}
#endif
return writer.WriteValueAsync(Convert.ToInt64(_value, CultureInfo.InvariantCulture), cancellationToken);
case JTokenType.Float:
- if (_value is decimal)
+ if (_value is decimal dec)
{
- return writer.WriteValueAsync((decimal)_value, cancellationToken);
+ return writer.WriteValueAsync(dec, cancellationToken);
}
- if (_value is double)
+ if (_value is double d)
{
- return writer.WriteValueAsync((double)_value, cancellationToken);
+ return writer.WriteValueAsync(d, cancellationToken);
}
- if (_value is float)
+ if (_value is float f)
{
- return writer.WriteValueAsync((float)_value, cancellationToken);
+ return writer.WriteValueAsync(f, cancellationToken);
}
return writer.WriteValueAsync(Convert.ToDouble(_value, CultureInfo.InvariantCulture), cancellationToken);
@@ -114,9 +114,9 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Boolean:
return writer.WriteValueAsync(Convert.ToBoolean(_value, CultureInfo.InvariantCulture), cancellationToken);
case JTokenType.Date:
- if (_value is DateTimeOffset)
+ if (_value is DateTimeOffset offset)
{
- return writer.WriteValueAsync((DateTimeOffset)_value, cancellationToken);
+ return writer.WriteValueAsync(offset, cancellationToken);
}
return writer.WriteValueAsync(Convert.ToDateTime(_value, CultureInfo.InvariantCulture), cancellationToken);
diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs
index 8e6b76f7..0232d2ab 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.cs
@@ -195,8 +195,7 @@ namespace Newtonsoft.Json.Linq
internal override bool DeepEquals(JToken node)
{
- JValue other = node as JValue;
- if (other == null)
+ if (!(node is JValue other))
{
return false;
}
@@ -228,10 +227,9 @@ namespace Newtonsoft.Json.Linq
// converting a fractional number to a BigInteger will lose the fraction
// check for fraction if result is two numbers are equal
- if (i2 is decimal)
+ if (i2 is decimal d1)
{
- decimal d = (decimal)i2;
- return (0m).CompareTo(Math.Abs(d - Math.Truncate(d)));
+ return (0m).CompareTo(Math.Abs(d1 - Math.Truncate(d1)));
}
else if (i2 is double || i2 is float)
{
@@ -261,14 +259,15 @@ namespace Newtonsoft.Json.Linq
switch (valueType)
{
case JTokenType.Integer:
+ {
#if HAVE_BIG_INTEGER
- if (objA is BigInteger)
+ if (objA is BigInteger integerA)
{
- return CompareBigInteger((BigInteger)objA, objB);
+ return CompareBigInteger(integerA, objB);
}
- if (objB is BigInteger)
+ if (objB is BigInteger integerB)
{
- return -CompareBigInteger((BigInteger)objB, objA);
+ return -CompareBigInteger(integerB, objA);
}
#endif
if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
@@ -283,15 +282,17 @@ namespace Newtonsoft.Json.Linq
{
return Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture));
}
+ }
case JTokenType.Float:
+ {
#if HAVE_BIG_INTEGER
- if (objA is BigInteger)
+ if (objA is BigInteger integerA)
{
- return CompareBigInteger((BigInteger)objA, objB);
+ return CompareBigInteger(integerA, objB);
}
- if (objB is BigInteger)
+ if (objB is BigInteger integerB)
{
- return -CompareBigInteger((BigInteger)objB, objA);
+ return -CompareBigInteger(integerB, objA);
}
#endif
if (objA is ulong || objB is ulong || objA is decimal || objB is decimal)
@@ -299,6 +300,7 @@ namespace Newtonsoft.Json.Linq
return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture));
}
return CompareFloat(objA, objB);
+ }
case JTokenType.Comment:
case JTokenType.String:
case JTokenType.Raw:
@@ -313,54 +315,48 @@ namespace Newtonsoft.Json.Linq
return b1.CompareTo(b2);
case JTokenType.Date:
#if HAVE_DATE_TIME_OFFSET
- if (objA is DateTime)
+ if (objA is DateTime dateA)
{
+#else
+ DateTime dateA = (DateTime)objA;
#endif
- DateTime date1 = (DateTime)objA;
- DateTime date2;
+ DateTime dateB;
#if HAVE_DATE_TIME_OFFSET
- if (objB is DateTimeOffset)
+ if (objB is DateTimeOffset offsetB)
{
- date2 = ((DateTimeOffset)objB).DateTime;
+ dateB = offsetB.DateTime;
}
else
#endif
{
- date2 = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
+ dateB = Convert.ToDateTime(objB, CultureInfo.InvariantCulture);
}
- return date1.CompareTo(date2);
+ return dateA.CompareTo(dateB);
#if HAVE_DATE_TIME_OFFSET
}
else
{
- DateTimeOffset date1 = (DateTimeOffset)objA;
- DateTimeOffset date2;
-
- if (objB is DateTimeOffset)
+ DateTimeOffset offsetA = (DateTimeOffset)objA;
+ if (!(objB is DateTimeOffset offsetB))
{
- date2 = (DateTimeOffset)objB;
- }
- else
- {
- date2 = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
+ offsetB = new DateTimeOffset(Convert.ToDateTime(objB, CultureInfo.InvariantCulture));
}
- return date1.CompareTo(date2);
+ return offsetA.CompareTo(offsetB);
}
#endif
case JTokenType.Bytes:
- byte[] bytes2 = objB as byte[];
- if (bytes2 == null)
+ if (!(objB is byte[] bytesB))
{
throw new ArgumentException("Object must be of type byte[].");
}
- byte[] bytes1 = objA as byte[];
- Debug.Assert(bytes1 != null);
+ byte[] bytesA = objA as byte[];
+ Debug.Assert(bytesA != null);
- return MiscellaneousUtils.ByteArrayCompare(bytes1, bytes2);
+ return MiscellaneousUtils.ByteArrayCompare(bytesA, bytesB);
case JTokenType.Guid:
if (!(objB is Guid))
{
@@ -747,22 +743,22 @@ namespace Newtonsoft.Json.Linq
writer.WriteUndefined();
return;
case JTokenType.Integer:
- if (_value is int)
+ if (_value is int i)
{
- writer.WriteValue((int)_value);
+ writer.WriteValue(i);
}
- else if (_value is long)
+ else if (_value is long l)
{
- writer.WriteValue((long)_value);
+ writer.WriteValue(l);
}
- else if (_value is ulong)
+ else if (_value is ulong ul)
{
- writer.WriteValue((ulong)_value);
+ writer.WriteValue(ul);
}
#if HAVE_BIG_INTEGER
- else if (_value is BigInteger)
+ else if (_value is BigInteger integer)
{
- writer.WriteValue((BigInteger)_value);
+ writer.WriteValue(integer);
}
#endif
else
@@ -771,17 +767,17 @@ namespace Newtonsoft.Json.Linq
}
return;
case JTokenType.Float:
- if (_value is decimal)
+ if (_value is decimal dec)
{
- writer.WriteValue((decimal)_value);
+ writer.WriteValue(dec);
}
- else if (_value is double)
+ else if (_value is double d)
{
- writer.WriteValue((double)_value);
+ writer.WriteValue(d);
}
- else if (_value is float)
+ else if (_value is float f)
{
- writer.WriteValue((float)_value);
+ writer.WriteValue(f);
}
else
{
@@ -796,9 +792,9 @@ namespace Newtonsoft.Json.Linq
return;
case JTokenType.Date:
#if HAVE_DATE_TIME_OFFSET
- if (_value is DateTimeOffset)
+ if (_value is DateTimeOffset offset)
{
- writer.WriteValue((DateTimeOffset)_value);
+ writer.WriteValue(offset);
}
else
#endif
@@ -936,8 +932,7 @@ namespace Newtonsoft.Json.Linq
return string.Empty;
}
- IFormattable formattable = _value as IFormattable;
- if (formattable != null)
+ if (_value is IFormattable formattable)
{
return formattable.ToString(format, formatProvider);
}
@@ -984,8 +979,7 @@ namespace Newtonsoft.Json.Linq
public override bool TryBinaryOperation(JValue instance, BinaryOperationBinder binder, object arg, out object result)
{
- JValue value = arg as JValue;
- object compareValue = value != null ? value.Value : arg;
+ object compareValue = arg is JValue value ? value.Value : arg;
switch (binder.Operation)
{
@@ -1095,14 +1089,12 @@ namespace Newtonsoft.Json.Linq
return TypeCode.Empty;
}
- IConvertible convertable = _value as IConvertible;
-
- if (convertable == null)
+ if (_value is IConvertible convertable)
{
- return TypeCode.Object;
+ return convertable.GetTypeCode();
}
- return convertable.GetTypeCode();
+ return TypeCode.Object;
}
bool IConvertible.ToBoolean(IFormatProvider provider)
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/ArraySliceFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/ArraySliceFilter.cs
index 0a514c5b..e6ee0b7b 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/ArraySliceFilter.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/ArraySliceFilter.cs
@@ -20,8 +20,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
foreach (JToken t in current)
{
- JArray a = t as JArray;
- if (a != null)
+ if (t is JArray a)
{
// set defaults for null arguments
int stepCount = Step ?? 1;
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs
index fdddbe89..6298909a 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs
@@ -12,8 +12,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
{
foreach (JToken t in current)
{
- JObject o = t as JObject;
- if (o != null)
+ if (t is JObject o)
{
if (Name != null)
{
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs
index b291f813..3d46708e 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/FieldMultipleFilter.cs
@@ -17,8 +17,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
{
foreach (JToken t in current)
{
- JObject o = t as JObject;
- if (o != null)
+ if (t is JObject o)
{
foreach (string name in Names)
{
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs b/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs
index 1f15f2ef..27986dc2 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/JPath.cs
@@ -406,7 +406,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
_currentIndex++;
- QueryExpression expression = ParseExpression(scan);
+ QueryExpression expression = ParseExpression();
_currentIndex++;
EnsureLength("Path ended with open indexer.");
@@ -433,7 +433,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
}
}
- private bool TryParseExpression(bool scan, out List expressionPath)
+ private bool TryParseExpression(out List expressionPath)
{
if (_expression[_currentIndex] == '$')
{
@@ -465,12 +465,11 @@ namespace Newtonsoft.Json.Linq.JsonPath
return new JsonException("Unexpected character while parsing path query: " + _expression[_currentIndex]);
}
- private object ParseSide(bool scan)
+ private object ParseSide()
{
EatWhitespace();
- List expressionPath;
- if (TryParseExpression(scan, out expressionPath))
+ if (TryParseExpression(out var expressionPath))
{
EatWhitespace();
EnsureLength("Path ended with open query.");
@@ -478,8 +477,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
return expressionPath;
}
- object value;
- if (TryParseValue(out value))
+ if (TryParseValue(out var value))
{
EatWhitespace();
EnsureLength("Path ended with open query.");
@@ -490,14 +488,14 @@ namespace Newtonsoft.Json.Linq.JsonPath
throw CreateUnexpectedCharacterException();
}
- private QueryExpression ParseExpression(bool scan)
+ private QueryExpression ParseExpression()
{
QueryExpression rootExpression = null;
CompositeExpression parentExpression = null;
while (_currentIndex < _expression.Length)
{
- object left = ParseSide(scan);
+ object left = ParseSide();
object right = null;
QueryOperator op;
@@ -511,7 +509,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
{
op = ParseOperator();
- right = ParseSide(scan);
+ right = ParseSide();
}
BooleanQueryExpression booleanExpression = new BooleanQueryExpression
@@ -603,17 +601,15 @@ namespace Newtonsoft.Json.Linq.JsonPath
{
string numberText = sb.ToString();
- if (numberText.IndexOfAny(new char[] { '.', 'E', 'e' }) != -1)
+ if (numberText.IndexOfAny(new[] { '.', 'E', 'e' }) != -1)
{
- double d;
- bool result = double.TryParse(numberText, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out d);
+ bool result = double.TryParse(numberText, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var d);
value = d;
return result;
}
else
{
- long l;
- bool result = long.TryParse(numberText, NumberStyles.Integer, CultureInfo.InvariantCulture, out l);
+ bool result = long.TryParse(numberText, NumberStyles.Integer, CultureInfo.InvariantCulture, out var l);
value = l;
return result;
}
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/PathFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/PathFilter.cs
index 34bdf943..6ea77c55 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/PathFilter.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/PathFilter.cs
@@ -10,10 +10,8 @@ namespace Newtonsoft.Json.Linq.JsonPath
protected static JToken GetTokenIndex(JToken t, bool errorWhenNoMatch, int index)
{
- JArray a = t as JArray;
- JConstructor c = t as JConstructor;
- if (a != null)
+ if (t is JArray a)
{
if (a.Count <= index)
{
@@ -27,7 +25,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
return a[index];
}
- else if (c != null)
+ else if (t is JConstructor c)
{
if (c.Count <= index)
{
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs b/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs
index 245bffe7..8028cedd 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/QueryExpression.cs
@@ -76,14 +76,12 @@ namespace Newtonsoft.Json.Linq.JsonPath
private IEnumerable GetResult(JToken root, JToken t, object o)
{
- JToken resultToken = o as JToken;
- if (resultToken != null)
+ if (o is JToken resultToken)
{
return new[] { resultToken };
}
- List pathFilters = o as List;
- if (pathFilters != null)
+ if (o is List pathFilters)
{
return JPath.Evaluate(pathFilters, root, t, false);
}
@@ -124,10 +122,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
private bool MatchTokens(JToken leftResult, JToken rightResult)
{
- JValue leftValue = leftResult as JValue;
- JValue rightValue = rightResult as JValue;
-
- if (leftValue != null && rightValue != null)
+ if (leftResult is JValue leftValue && rightResult is JValue rightValue)
{
switch (Operator)
{
@@ -209,9 +204,9 @@ namespace Newtonsoft.Json.Linq.JsonPath
using (StringWriter writer = StringUtils.CreateStringWriter(64))
{
#if HAVE_DATE_TIME_OFFSET
- if (value.Value is DateTimeOffset)
+ if (value.Value is DateTimeOffset offset)
{
- DateTimeUtils.WriteDateTimeOffsetString(writer, (DateTimeOffset)value.Value, DateFormatHandling.IsoDateFormat, null, CultureInfo.InvariantCulture);
+ DateTimeUtils.WriteDateTimeOffsetString(writer, offset, DateFormatHandling.IsoDateFormat, null, CultureInfo.InvariantCulture);
}
else
#endif
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs
index 53dcaec0..073edd9d 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/ScanFilter.cs
@@ -16,22 +16,22 @@ namespace Newtonsoft.Json.Linq.JsonPath
}
JToken value = c;
- JContainer container = c as JContainer;
while (true)
{
+ JContainer container = value as JContainer;
+
value = GetNextScanValue(c, container, value);
if (value == null)
{
break;
}
- JProperty e = value as JProperty;
- if (e != null)
+ if (value is JProperty property)
{
- if (e.Name == Name)
+ if (property.Name == Name)
{
- yield return e.Value;
+ yield return property.Value;
}
}
else
@@ -41,8 +41,6 @@ namespace Newtonsoft.Json.Linq.JsonPath
yield return value;
}
}
-
- container = value as JContainer;
}
}
}
diff --git a/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs b/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs
index 304968c7..934b2965 100644
--- a/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs
+++ b/Src/Newtonsoft.Json/Linq/JsonPath/ScanMultipleFilter.cs
@@ -11,29 +11,28 @@ namespace Newtonsoft.Json.Linq.JsonPath
foreach (JToken c in current)
{
JToken value = c;
- JContainer container = c as JContainer;
while (true)
{
+ JContainer container = value as JContainer;
+
value = GetNextScanValue(c, container, value);
if (value == null)
{
break;
}
- JProperty e = value as JProperty;
- if (e != null)
+ if (value is JProperty property)
{
foreach (string name in Names)
{
- if (e.Name == name)
+ if (property.Name == name)
{
- yield return e.Value;
+ yield return property.Value;
}
}
}
- container = value as JContainer;
}
}
}
diff --git a/Src/Newtonsoft.Json/Linq/LineInfoHandling.cs b/Src/Newtonsoft.Json/Linq/LineInfoHandling.cs
new file mode 100644
index 00000000..d0d825f2
--- /dev/null
+++ b/Src/Newtonsoft.Json/Linq/LineInfoHandling.cs
@@ -0,0 +1,18 @@
+namespace Newtonsoft.Json.Linq
+{
+ ///
+ /// Specifies how line information is handled when loading JSON.
+ ///
+ public enum LineInfoHandling
+ {
+ ///
+ /// Ignore line information.
+ ///
+ Ignore = 0,
+
+ ///
+ /// Load line information.
+ ///
+ Load = 1
+ }
+}
\ No newline at end of file