diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs index f3c00048..0b3fe168 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs @@ -262,6 +262,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(0, result.Count); } +#nullable enable [Test] public void Casting() { @@ -273,44 +274,44 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(new DateTimeOffset(2000, 12, 20, 0, 0, 0, TimeSpan.Zero), (DateTimeOffset)new JValue(new DateTime(2000, 12, 20, 0, 0, 0, DateTimeKind.Utc))); Assert.AreEqual(new DateTimeOffset(2000, 12, 20, 23, 50, 10, TimeSpan.Zero), (DateTimeOffset)new JValue(new DateTimeOffset(2000, 12, 20, 23, 50, 10, TimeSpan.Zero))); Assert.AreEqual(null, (DateTimeOffset?)new JValue((DateTimeOffset?)null)); - Assert.AreEqual(null, (DateTimeOffset?)(JValue)null); + Assert.AreEqual(null, (DateTimeOffset?)(JValue?)null); #endif Assert.AreEqual(true, (bool)new JValue(true)); Assert.AreEqual(true, (bool?)new JValue(true)); - Assert.AreEqual(null, (bool?)((JValue)null)); + Assert.AreEqual(null, (bool?)((JValue?)null)); Assert.AreEqual(null, (bool?)JValue.CreateNull()); Assert.AreEqual(10, (long)new JValue(10)); Assert.AreEqual(null, (long?)new JValue((long?)null)); - Assert.AreEqual(null, (long?)(JValue)null); + Assert.AreEqual(null, (long?)(JValue?)null); Assert.AreEqual(null, (int?)new JValue((int?)null)); - Assert.AreEqual(null, (int?)(JValue)null); + Assert.AreEqual(null, (int?)(JValue?)null); Assert.AreEqual(null, (DateTime?)new JValue((DateTime?)null)); - Assert.AreEqual(null, (DateTime?)(JValue)null); + Assert.AreEqual(null, (DateTime?)(JValue?)null); Assert.AreEqual(null, (short?)new JValue((short?)null)); - Assert.AreEqual(null, (short?)(JValue)null); + Assert.AreEqual(null, (short?)(JValue?)null); Assert.AreEqual(null, (float?)new JValue((float?)null)); - Assert.AreEqual(null, (float?)(JValue)null); + Assert.AreEqual(null, (float?)(JValue?)null); Assert.AreEqual(null, (double?)new JValue((double?)null)); - Assert.AreEqual(null, (double?)(JValue)null); + Assert.AreEqual(null, (double?)(JValue?)null); Assert.AreEqual(null, (decimal?)new JValue((decimal?)null)); - Assert.AreEqual(null, (decimal?)(JValue)null); + Assert.AreEqual(null, (decimal?)(JValue?)null); Assert.AreEqual(null, (uint?)new JValue((uint?)null)); - Assert.AreEqual(null, (uint?)(JValue)null); + Assert.AreEqual(null, (uint?)(JValue?)null); Assert.AreEqual(null, (sbyte?)new JValue((sbyte?)null)); - Assert.AreEqual(null, (sbyte?)(JValue)null); + Assert.AreEqual(null, (sbyte?)(JValue?)null); Assert.AreEqual(null, (byte?)new JValue((byte?)null)); - Assert.AreEqual(null, (byte?)(JValue)null); + Assert.AreEqual(null, (byte?)(JValue?)null); Assert.AreEqual(null, (ulong?)new JValue((ulong?)null)); - Assert.AreEqual(null, (ulong?)(JValue)null); + Assert.AreEqual(null, (ulong?)(JValue?)null); Assert.AreEqual(null, (uint?)new JValue((uint?)null)); - Assert.AreEqual(null, (uint?)(JValue)null); + Assert.AreEqual(null, (uint?)(JValue?)null); Assert.AreEqual(11.1f, (float)new JValue(11.1)); Assert.AreEqual(float.MinValue, (float)new JValue(float.MinValue)); Assert.AreEqual(1.1, (double)new JValue(1.1)); Assert.AreEqual(uint.MaxValue, (uint)new JValue(uint.MaxValue)); Assert.AreEqual(ulong.MaxValue, (ulong)new JValue(ulong.MaxValue)); Assert.AreEqual(ulong.MaxValue, (ulong)new JProperty("Test", new JValue(ulong.MaxValue))); - Assert.AreEqual(null, (string)new JValue((string)null)); + Assert.AreEqual(null, (string?)new JValue((string?)null)); Assert.AreEqual(5m, (decimal)(new JValue(5L))); Assert.AreEqual(5m, (decimal?)(new JValue(5L))); Assert.AreEqual(5f, (float)(new JValue(5L))); @@ -322,15 +323,15 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(null, (sbyte?)JValue.CreateNull()); - Assert.AreEqual("1", (string)(new JValue(1))); - Assert.AreEqual("1", (string)(new JValue(1.0))); - Assert.AreEqual("1.0", (string)(new JValue(1.0m))); - Assert.AreEqual("True", (string)(new JValue(true))); - Assert.AreEqual(null, (string)(JValue.CreateNull())); - Assert.AreEqual(null, (string)(JValue)null); - Assert.AreEqual("12/12/2000 12:12:12", (string)(new JValue(new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc)))); + Assert.AreEqual("1", (string?)(new JValue(1))); + Assert.AreEqual("1", (string?)(new JValue(1.0))); + Assert.AreEqual("1.0", (string?)(new JValue(1.0m))); + Assert.AreEqual("True", (string?)(new JValue(true))); + Assert.AreEqual(null, (string?)(JValue.CreateNull())); + Assert.AreEqual(null, (string?)(JValue?)null); + Assert.AreEqual("12/12/2000 12:12:12", (string?)(new JValue(new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc)))); #if !NET20 - Assert.AreEqual("12/12/2000 12:12:12 +00:00", (string)(new JValue(new DateTimeOffset(2000, 12, 12, 12, 12, 12, TimeSpan.Zero)))); + Assert.AreEqual("12/12/2000 12:12:12 +00:00", (string?)(new JValue(new DateTimeOffset(2000, 12, 12, 12, 12, 12, TimeSpan.Zero)))); #endif Assert.AreEqual(true, (bool)(new JValue(1))); Assert.AreEqual(true, (bool)(new JValue(1.0))); @@ -347,46 +348,46 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(1m, (decimal)(new JValue("1"))); Assert.AreEqual(1m, (decimal)(new JValue(true))); Assert.AreEqual(TimeSpan.FromMinutes(1), (TimeSpan)(new JValue(TimeSpan.FromMinutes(1)))); - Assert.AreEqual("00:01:00", (string)(new JValue(TimeSpan.FromMinutes(1)))); + Assert.AreEqual("00:01:00", (string?)(new JValue(TimeSpan.FromMinutes(1)))); Assert.AreEqual(TimeSpan.FromMinutes(1), (TimeSpan)(new JValue("00:01:00"))); - Assert.AreEqual("46efe013-b56a-4e83-99e4-4dce7678a5bc", (string)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC")))); - Assert.AreEqual("http://www.google.com/", (string)(new JValue(new Uri("http://www.google.com")))); + Assert.AreEqual("46efe013-b56a-4e83-99e4-4dce7678a5bc", (string?)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC")))); + Assert.AreEqual("http://www.google.com/", (string?)(new JValue(new Uri("http://www.google.com")))); Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid)(new JValue("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"))); Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC")))); - Assert.AreEqual(new Uri("http://www.google.com"), (Uri)(new JValue("http://www.google.com"))); - Assert.AreEqual(new Uri("http://www.google.com"), (Uri)(new JValue(new Uri("http://www.google.com")))); - Assert.AreEqual(null, (Uri)(JValue.CreateNull())); - Assert.AreEqual(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi")), (string)(new JValue(Encoding.UTF8.GetBytes("hi")))); - CollectionAssert.AreEquivalent((byte[])Encoding.UTF8.GetBytes("hi"), (byte[])(new JValue(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi"))))); + Assert.AreEqual(new Uri("http://www.google.com"), (Uri?)(new JValue("http://www.google.com"))); + Assert.AreEqual(new Uri("http://www.google.com"), (Uri?)(new JValue(new Uri("http://www.google.com")))); + Assert.AreEqual(null, (Uri?)(JValue.CreateNull())); + Assert.AreEqual(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi")), (string?)(new JValue(Encoding.UTF8.GetBytes("hi")))); + CollectionAssert.AreEquivalent((byte[])Encoding.UTF8.GetBytes("hi"), (byte[]?)(new JValue(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi"))))); Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC").ToByteArray()))); Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid?)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC").ToByteArray()))); Assert.AreEqual((sbyte?)1, (sbyte?)(new JValue((short?)1))); - Assert.AreEqual(null, (Uri)(JValue)null); - Assert.AreEqual(null, (int?)(JValue)null); - Assert.AreEqual(null, (uint?)(JValue)null); - Assert.AreEqual(null, (Guid?)(JValue)null); - Assert.AreEqual(null, (TimeSpan?)(JValue)null); - Assert.AreEqual(null, (byte[])(JValue)null); - Assert.AreEqual(null, (bool?)(JValue)null); - Assert.AreEqual(null, (char?)(JValue)null); - Assert.AreEqual(null, (DateTime?)(JValue)null); + Assert.AreEqual(null, (Uri?)(JValue?)null); + Assert.AreEqual(null, (int?)(JValue?)null); + Assert.AreEqual(null, (uint?)(JValue?)null); + Assert.AreEqual(null, (Guid?)(JValue?)null); + Assert.AreEqual(null, (TimeSpan?)(JValue?)null); + Assert.AreEqual(null, (byte[]?)(JValue?)null); + Assert.AreEqual(null, (bool?)(JValue?)null); + Assert.AreEqual(null, (char?)(JValue?)null); + Assert.AreEqual(null, (DateTime?)(JValue?)null); #if !NET20 - Assert.AreEqual(null, (DateTimeOffset?)(JValue)null); + Assert.AreEqual(null, (DateTimeOffset?)(JValue?)null); #endif - Assert.AreEqual(null, (short?)(JValue)null); - Assert.AreEqual(null, (ushort?)(JValue)null); - Assert.AreEqual(null, (byte?)(JValue)null); - Assert.AreEqual(null, (byte?)(JValue)null); - Assert.AreEqual(null, (sbyte?)(JValue)null); - Assert.AreEqual(null, (sbyte?)(JValue)null); - Assert.AreEqual(null, (long?)(JValue)null); - Assert.AreEqual(null, (ulong?)(JValue)null); - Assert.AreEqual(null, (double?)(JValue)null); - Assert.AreEqual(null, (float?)(JValue)null); + Assert.AreEqual(null, (short?)(JValue?)null); + Assert.AreEqual(null, (ushort?)(JValue?)null); + Assert.AreEqual(null, (byte?)(JValue?)null); + Assert.AreEqual(null, (byte?)(JValue?)null); + Assert.AreEqual(null, (sbyte?)(JValue?)null); + Assert.AreEqual(null, (sbyte?)(JValue?)null); + Assert.AreEqual(null, (long?)(JValue?)null); + Assert.AreEqual(null, (ulong?)(JValue?)null); + Assert.AreEqual(null, (double?)(JValue?)null); + Assert.AreEqual(null, (float?)(JValue?)null); byte[] data = new byte[0]; - Assert.AreEqual(data, (byte[])(new JValue(data))); + Assert.AreEqual(data, (byte[]?)(new JValue(data))); Assert.AreEqual(5, (int)(new JValue(StringComparison.OrdinalIgnoreCase))); @@ -404,19 +405,20 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(new BigInteger(123), (new JValue(123)).ToObject()); Assert.AreEqual(null, (JValue.CreateNull()).ToObject()); - byte[] intData = BigInteger.Parse(bigIntegerText).ToByteArray(); + byte[]? intData = BigInteger.Parse(bigIntegerText).ToByteArray(); Assert.AreEqual(BigInteger.Parse(bigIntegerText), (new JValue(intData)).ToObject()); Assert.AreEqual(4.0d, (double)(new JValue(new BigInteger(4.5d)))); Assert.AreEqual(true, (bool)(new JValue(new BigInteger(1)))); Assert.AreEqual(long.MaxValue, (long)(new JValue(new BigInteger(long.MaxValue)))); Assert.AreEqual(long.MaxValue, (long)(new JValue(new BigInteger(new byte[] { 255, 255, 255, 255, 255, 255, 255, 127 })))); - Assert.AreEqual("9223372036854775807", (string)(new JValue(new BigInteger(long.MaxValue)))); + Assert.AreEqual("9223372036854775807", (string?)(new JValue(new BigInteger(long.MaxValue)))); - intData = (byte[])(new JValue(new BigInteger(long.MaxValue))); + intData = (byte[]?)new JValue(new BigInteger(long.MaxValue)); CollectionAssert.AreEqual(new byte[] { 255, 255, 255, 255, 255, 255, 255, 127 }, intData); #endif } +#nullable disable [Test] public void FailedCasting() @@ -536,6 +538,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(null, (JValue.CreateNull().ToObject(typeof(StringComparison?)))); } +#nullable enable [Test] public void ImplicitCastingTo() { @@ -577,7 +580,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(JToken.DeepEquals(new JValue(uint.MaxValue), (JValue)uint.MaxValue)); Assert.IsTrue(JToken.DeepEquals(new JValue(ulong.MaxValue), (JValue)ulong.MaxValue)); Assert.IsTrue(JToken.DeepEquals(new JValue(ulong.MinValue), (JValue)ulong.MinValue)); - Assert.IsTrue(JToken.DeepEquals(new JValue((string)null), (JValue)(string)null)); + Assert.IsTrue(JToken.DeepEquals(new JValue((string?)null), (JValue)(string?)null)); Assert.IsTrue(JToken.DeepEquals(new JValue((DateTime?)null), (JValue)(DateTime?)null)); Assert.IsTrue(JToken.DeepEquals(new JValue(decimal.MaxValue), (JValue)decimal.MaxValue)); Assert.IsTrue(JToken.DeepEquals(new JValue(decimal.MaxValue), (JValue)(decimal?)decimal.MaxValue)); @@ -587,7 +590,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(double?)null)); Assert.IsFalse(JToken.DeepEquals(new JValue(true), (JValue)(bool?)null)); - Assert.IsFalse(JToken.DeepEquals(JValue.CreateNull(), (JValue)(object)null)); + Assert.IsFalse(JToken.DeepEquals(JValue.CreateNull(), (JValue?)(object?)null)); byte[] emptyData = new byte[0]; Assert.IsTrue(JToken.DeepEquals(new JValue(emptyData), (JValue)emptyData)); @@ -599,9 +602,10 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(JToken.DeepEquals(new JValue(TimeSpan.FromMinutes(1)), (JValue)(TimeSpan?)TimeSpan.FromMinutes(1))); Assert.IsTrue(JToken.DeepEquals(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC")), (JValue)new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"))); Assert.IsTrue(JToken.DeepEquals(new JValue(new Uri("http://www.google.com")), (JValue)new Uri("http://www.google.com"))); - Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(Uri)null)); + Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(Uri?)null)); Assert.IsTrue(JToken.DeepEquals(JValue.CreateNull(), (JValue)(Guid?)null)); } +#nullable disable [Test] public void Root() diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index 8d0dd585..6cb80e85 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -2,7 +2,7 @@ net46;net451;net452;net40;net35;net20;netcoreapp3.0;netcoreapp1.1;netcoreapp1.0 $(TestFrameworks) - latest + 8.0 1.0 James Newton-King Newtonsoft diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 5b229651..611ba8e7 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -153,7 +153,7 @@ namespace Newtonsoft.Json.Linq /// The first to compare. /// The second to compare. /// true if the tokens are equal; otherwise false. - public static bool DeepEquals(JToken t1, JToken t2) + public static bool DeepEquals(JToken? t1, JToken? t2) { return (t1 == t2 || (t1 != null && t2 != null && t1.DeepEquals(t2))); } @@ -232,7 +232,7 @@ namespace Newtonsoft.Json.Linq /// Adds the specified content immediately after this token. /// /// A content object that contains simple content or a collection of content objects to be added after this token. - public void AddAfterSelf(object content) + public void AddAfterSelf(object? content) { if (_parent == null) { @@ -247,7 +247,7 @@ namespace Newtonsoft.Json.Linq /// Adds the specified content immediately before this token. /// /// A content object that contains simple content or a collection of content objects to be added before this token. - public void AddBeforeSelf(object content) + public void AddBeforeSelf(object? content) { if (_parent == null) { @@ -538,7 +538,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator bool?(JToken value) + public static explicit operator bool?(JToken? value) { if (value == null) { @@ -589,7 +589,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator DateTime?(JToken value) + public static explicit operator DateTime?(JToken? value) { if (value == null) { @@ -618,7 +618,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator DateTimeOffset?(JToken value) + public static explicit operator DateTimeOffset?(JToken? value) { if (value == null) { @@ -654,7 +654,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator decimal?(JToken value) + public static explicit operator decimal?(JToken? value) { if (value == null) { @@ -682,7 +682,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator double?(JToken value) + public static explicit operator double?(JToken? value) { if (value == null) { @@ -710,7 +710,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator char?(JToken value) + public static explicit operator char?(JToken? value) { if (value == null) { @@ -879,7 +879,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator int?(JToken value) + public static explicit operator int?(JToken? value) { if (value == null) { @@ -907,7 +907,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator short?(JToken value) + public static explicit operator short?(JToken? value) { if (value == null) { @@ -936,7 +936,7 @@ namespace Newtonsoft.Json.Linq /// The value. /// The result of the conversion. [CLSCompliant(false)] - public static explicit operator ushort?(JToken value) + public static explicit operator ushort?(JToken? value) { if (value == null) { @@ -964,7 +964,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator byte?(JToken value) + public static explicit operator byte?(JToken? value) { if (value == null) { @@ -993,7 +993,7 @@ namespace Newtonsoft.Json.Linq /// The value. /// The result of the conversion. [CLSCompliant(false)] - public static explicit operator sbyte?(JToken value) + public static explicit operator sbyte?(JToken? value) { if (value == null) { @@ -1044,7 +1044,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator long?(JToken value) + public static explicit operator long?(JToken? value) { if (value == null) { @@ -1072,7 +1072,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator float?(JToken value) + public static explicit operator float?(JToken? value) { if (value == null) { @@ -1124,7 +1124,7 @@ namespace Newtonsoft.Json.Linq /// The value. /// The result of the conversion. [CLSCompliant(false)] - public static explicit operator uint?(JToken value) + public static explicit operator uint?(JToken? value) { if (value == null) { @@ -1153,7 +1153,7 @@ namespace Newtonsoft.Json.Linq /// The value. /// The result of the conversion. [CLSCompliant(false)] - public static explicit operator ulong?(JToken value) + public static explicit operator ulong?(JToken? value) { if (value == null) { @@ -1227,7 +1227,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator string?(JToken value) + public static explicit operator string?(JToken? value) { if (value == null) { @@ -1313,7 +1313,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator byte[]?(JToken value) + public static explicit operator byte[]?(JToken? value) { if (value == null) { @@ -1371,7 +1371,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator Guid?(JToken value) + public static explicit operator Guid?(JToken? value) { if (value == null) { @@ -1418,7 +1418,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator TimeSpan?(JToken value) + public static explicit operator TimeSpan?(JToken? value) { if (value == null) { @@ -1444,7 +1444,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// The result of the conversion. - public static explicit operator Uri?(JToken value) + public static explicit operator Uri?(JToken? value) { if (value == null) { @@ -1773,7 +1773,7 @@ namespace Newtonsoft.Json.Linq /// /// The value to create a from. /// The initialized with the specified value. - public static implicit operator JToken(string value) + public static implicit operator JToken(string? value) { return new JValue(value); } @@ -1815,7 +1815,7 @@ namespace Newtonsoft.Json.Linq /// /// The value to create a from. /// The initialized with the specified value. - public static implicit operator JToken(Uri value) + public static implicit operator JToken(Uri? value) { return new JValue(value); } diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index fba0af28..ae7c6211 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -154,7 +154,7 @@ namespace Newtonsoft.Json.Linq /// Initializes a new instance of the class with the given value. /// /// The value. - public JValue(string value) + public JValue(string? value) : this(value, JTokenType.String) { } @@ -172,7 +172,7 @@ namespace Newtonsoft.Json.Linq /// Initializes a new instance of the class with the given value. /// /// The value. - public JValue(Uri value) + public JValue(Uri? value) : this(value, (value != null) ? JTokenType.Uri : JTokenType.Null) { } @@ -576,7 +576,7 @@ namespace Newtonsoft.Json.Linq /// /// The value. /// A string with the given value. - public static JValue CreateString(string value) + public static JValue CreateString(string? value) { return new JValue(value, JTokenType.String); }