-Added IgnoreSerializableInterface to DefaultContractResolver

-Changed serializing ISerializable types under partial trust to error to fix security issue
-Fixed LinqBridge collision error in .NET 2.0 by moving types to a different namespace
-Fixed JObject.Keys error when object has no items
This commit is contained in:
James Newton-King
2012-03-18 16:24:30 +13:00
parent 9c7fb730f2
commit 8471c4ffe1
162 changed files with 3550 additions and 3566 deletions
@@ -24,9 +24,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
@@ -25,7 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
@@ -39,6 +38,11 @@ using System.IO;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Tests.TestObjects;
using System.Globalization;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Bson
{
@@ -6,7 +6,6 @@ using System.Data.Linq;
#if !(SILVERLIGHT || NETFX_CORE)
using System.Data.SqlTypes;
#endif
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
@@ -16,7 +15,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
using NUnit.Framework;
@@ -1,8 +1,5 @@
#if !(SILVERLIGHT || NETFX_CORE)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
using NUnit.Framework;
@@ -1,9 +1,5 @@
#if !(SILVERLIGHT || NETFX_CORE)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -11,7 +7,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using System.Data;
#endif
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
@@ -38,7 +35,6 @@ using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Utilities;
using System.Globalization;
using System.Xml;
namespace Newtonsoft.Json.Tests.Converters
{
@@ -24,10 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -36,6 +32,7 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
#if !NETFX_CORE
using NUnit.Framework;
@@ -7,8 +7,6 @@ using System.Data.Linq;
using System.Data.SqlTypes;
#endif
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Converters;
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
using NUnit.Framework;
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
using NUnit.Framework;
@@ -35,7 +32,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#if !NETFX_CORE
using NUnit.Framework;
@@ -23,10 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#endif
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
@@ -24,10 +24,6 @@
#endregion
#if !PocketPC && !SILVERLIGHT && !NETFX_CORE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Web.UI;
using Newtonsoft.Json.Linq;
@@ -24,10 +24,6 @@
#endregion
#if !SILVERLIGHT && !NETFX_CORE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -11,6 +9,11 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
#if !NETFX_CORE
using NUnit.Framework;
@@ -11,6 +9,11 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using System.IO;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
+19 -4
View File
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
@@ -12,19 +11,35 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
#if !PocketPC && !SILVERLIGHT && !NETFX_CORE
using System.Web.UI;
#endif
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JObjectTests : TestFixtureBase
{
[Test]
public void Keys()
{
var o = new JObject();
var d = (IDictionary<string, JToken>) o;
Assert.AreEqual(0, d.Keys.Count);
o["value"] = true;
Assert.AreEqual(1, d.Keys.Count);
}
[Test]
public void TryGetValue()
{
+5 -7
View File
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -12,9 +8,11 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.IO;
using System.Collections;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
@@ -2,8 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
#if !NETFX_CORE
using NUnit.Framework;
+1 -5
View File
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -25,7 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
@@ -37,6 +36,11 @@ using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using System.IO;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
@@ -36,7 +36,11 @@ using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Linq;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
@@ -25,7 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
@@ -36,6 +35,11 @@ using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using System.Globalization;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
@@ -26,21 +26,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using System.IO;
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using System.Xml;
using System.IO;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Tests.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
@@ -72,5 +72,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.8.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.0.8.14715")]
[assembly: AssemblyFileVersion("4.0.8.14718")]
#endif
@@ -25,8 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -40,10 +40,14 @@ using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Schema;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Text;
using Extensions=Newtonsoft.Json.Schema.Extensions;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Schema
{
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#if !NETFX_CORE
using NUnit.Framework;
@@ -23,10 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#if !NETFX_CORE
using NUnit.Framework;
@@ -23,11 +23,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#if !NETFX_CORE
using NUnit.Framework;
@@ -25,8 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Serialization;
#if !NETFX_CORE
using NUnit.Framework;
@@ -23,10 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -52,11 +52,11 @@ using System.Xml.Serialization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Linq;
using System.Linq;
using Newtonsoft.Json.Converters;
#if !PocketPC && !NET20 && !WINDOWS_PHONE
using System.Runtime.Serialization.Json;
#endif
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using System.Runtime.Serialization;
using System.Globalization;
@@ -72,6 +72,11 @@ using System.Linq.Expressions;
using System.Dynamic;
using System.ComponentModel;
#endif
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Serialization
{
@@ -2789,6 +2794,86 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
}
#if DEBUG
[Test]
public void SerializeISerializableInPartialTrustWithIgnoreInterface()
{
try
{
JsonTypeReflector.SetFullyTrusted(false);
ISerializableTestObject value = new ISerializableTestObject("string!", 0, default(DateTimeOffset), null);
string json = JsonConvert.SerializeObject(value, new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver(false)
{
IgnoreSerializableInterface = true
}
});
Assert.AreEqual("{}", json);
value = JsonConvert.DeserializeObject<ISerializableTestObject>("{booleanValue:true}", new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver(false)
{
IgnoreSerializableInterface = true
}
});
Assert.IsNotNull(value);
Assert.AreEqual(false, value._booleanValue);
}
finally
{
JsonTypeReflector.SetFullyTrusted(true);
}
}
[Test]
public void SerializeISerializableInPartialTrust()
{
try
{
ExceptionAssert.Throws<JsonSerializationException>(
@"Type 'Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+ISerializableTestObject' implements ISerializable but cannot be deserialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add to JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.",
() =>
{
JsonTypeReflector.SetFullyTrusted(false);
JsonConvert.DeserializeObject<ISerializableTestObject>("{booleanValue:true}");
});
}
finally
{
JsonTypeReflector.SetFullyTrusted(true);
}
}
[Test]
public void DeserializeISerializableInPartialTrust()
{
try
{
ExceptionAssert.Throws<JsonSerializationException>(
@"Type 'Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+ISerializableTestObject' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.
To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add to JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.",
() =>
{
JsonTypeReflector.SetFullyTrusted(false);
ISerializableTestObject value = new ISerializableTestObject("string!", 0, default(DateTimeOffset), null);
JsonConvert.SerializeObject(value);
});
}
finally
{
JsonTypeReflector.SetFullyTrusted(true);
}
}
#endif
[Test]
public void SerializeISerializableTestObject_IsoDate()
{
@@ -26,8 +26,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
@@ -36,7 +34,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Serialization
{
@@ -26,7 +26,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Tests.TestObjects;
@@ -25,8 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
@@ -36,7 +34,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Serialization;
using System.IO;
using ErrorEventArgs=Newtonsoft.Json.Serialization.ErrorEventArgs;
@@ -27,12 +27,9 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
@@ -42,8 +39,6 @@ using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttrib
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests.Serialization
{
@@ -26,9 +26,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
+6 -1
View File
@@ -27,7 +27,10 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
#if NET20
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities.LinqBridge;
#endif
using System.Text;
using System.Threading;
#if !NETFX_CORE
@@ -75,12 +78,14 @@ namespace Newtonsoft.Json.Tests
#endif
}
#if NETFX_CORE
public static class Console
{
public static void WriteLine(params object[] args)
{
}
}
#endif
public static class CustomAssert
{
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
public class CircularReferenceClass
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
[JsonObject(Id = "MyExplicitId")]
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public abstract class ContentBaseClass
{
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class ContentSubClass : ContentBaseClass
{
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
[JsonObject(IsReference = true)]
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class JaggedArray
{
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json.Serialization;
namespace Newtonsoft.Json.Tests.TestObjects
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class PersonPropertyClass
{
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
public class PrivateMembersClass
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class PublicParametizedConstructorTestClass
{
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class PublicParametizedConstructorWithNonPropertyParameterTestClass
{
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -25,9 +25,7 @@
#if !PocketPC
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json.Serialization;
namespace Newtonsoft.Json.Tests.TestObjects
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class Shortie
{
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.TestObjects
namespace Newtonsoft.Json.Tests.TestObjects
{
public class WagePerson : Person
{
@@ -25,12 +25,7 @@
#if !PocketPC && !SILVERLIGHT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Newtonsoft.Json.Tests.Linq;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -38,6 +33,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Tests.Serialization;
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
-3
View File
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Bson
@@ -23,11 +23,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json
{
/// <summary>
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Bson;
using System.Globalization;
using Newtonsoft.Json.Utilities;
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Converters
{
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Reflection;
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Bson;
using System.Globalization;
@@ -26,10 +26,14 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Newtonsoft.Json.Utilities;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Converters
{
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using Newtonsoft.Json.Utilities;
@@ -32,7 +32,11 @@ using System.Xml;
using System.Xml.Linq;
#endif
using Newtonsoft.Json.Utilities;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Converters
{
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json
{
+1 -6
View File
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json
namespace Newtonsoft.Json
{
/// <summary>
/// Provides an interface to enable a class to return line and position information.
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json
{
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json
{
@@ -24,9 +24,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json
{
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Globalization;
+5 -2
View File
@@ -27,9 +27,12 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json
{
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization.Formatters;
using System.Text;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities;
using System.Runtime.Serialization;
namespace Newtonsoft.Json
+5 -2
View File
@@ -25,14 +25,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Utilities;
using System.Globalization;
using System.Text.RegularExpressions;
using System.IO;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json
{
+5 -4
View File
@@ -25,16 +25,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Linq;
using System.Globalization;
#if NETFX_CORE
using IConvertible = Newtonsoft.Json.Utilities.Convertible;
#endif
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json
{
+5 -3
View File
@@ -25,11 +25,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Collections;
using System.Globalization;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Linq
{
+1 -4
View File
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace Newtonsoft.Json.Linq
{
-3
View File
@@ -25,9 +25,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.IO;
using System.Globalization;
-2
View File
@@ -25,8 +25,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Globalization;
+6 -3
View File
@@ -25,14 +25,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Specialized;
using System.Threading;
using Newtonsoft.Json.Utilities;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Specialized;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Linq
{
+5 -3
View File
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
using System.Text;
#endif
using Newtonsoft.Json.Utilities;
using System.Collections;
+16 -45
View File
@@ -32,10 +32,14 @@ using System.ComponentModel;
using System.Dynamic;
using System.Linq.Expressions;
#endif
using System.Linq;
using System.IO;
using Newtonsoft.Json.Utilities;
using System.Globalization;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Linq
{
@@ -50,40 +54,7 @@ namespace Newtonsoft.Json.Linq
, INotifyPropertyChanging
#endif
{
private class JPropertKeyedCollection : KeyedCollection<string, JToken>
{
public JPropertKeyedCollection(IEqualityComparer<string> comparer)
: base(comparer)
{
}
protected override string GetKeyForItem(JToken item)
{
return ((JProperty) item).Name;
}
protected override void InsertItem(int index, JToken item)
{
if (Dictionary == null)
{
base.InsertItem(index, item);
}
else
{
// need to override so that the dictionary key is always set rather than added
string keyForItem = GetKeyForItem(item);
Dictionary[keyForItem] = item;
Items.Insert(index, item);
}
}
public new IDictionary<string, JToken> Dictionary
{
get { return base.Dictionary; }
}
}
private readonly JPropertKeyedCollection _properties = new JPropertKeyedCollection(StringComparer.Ordinal);
private readonly JPropertyKeyedCollection _properties = new JPropertyKeyedCollection();
/// <summary>
/// Gets the container's children tokens.
@@ -172,7 +143,7 @@ namespace Newtonsoft.Json.Linq
return;
}
if (_properties.Dictionary != null && _properties.Dictionary.TryGetValue(newProperty.Name, out existing))
if (_properties.TryGetValue(newProperty.Name, out existing))
throw new ArgumentException("Can not add property {0} to {1}. Property with the same name already exists on object.".FormatWith(CultureInfo.InvariantCulture, newProperty.Name, GetType()));
}
@@ -224,13 +195,11 @@ namespace Newtonsoft.Json.Linq
/// <returns>A <see cref="JProperty"/> with the specified name or null.</returns>
public JProperty Property(string name)
{
if (_properties.Dictionary == null)
return null;
if (name == null)
return null;
JToken property;
_properties.Dictionary.TryGetValue(name, out property);
_properties.TryGetValue(name, out property);
return (JProperty)property;
}
@@ -406,15 +375,13 @@ namespace Newtonsoft.Json.Linq
bool IDictionary<string, JToken>.ContainsKey(string key)
{
if (_properties.Dictionary == null)
return false;
return _properties.Dictionary.ContainsKey(key);
return _properties.Contains(key);
}
ICollection<string> IDictionary<string, JToken>.Keys
{
get { return _properties.Dictionary.Keys; }
// todo: make order the collection returned match JObject order
get { return _properties.Keys; }
}
/// <summary>
@@ -453,7 +420,11 @@ namespace Newtonsoft.Json.Linq
ICollection<JToken> IDictionary<string, JToken>.Values
{
get { return _properties.Dictionary.Values; }
get
{
// todo: need to wrap _properties.Values with a collection to get the JProperty value
throw new NotImplementedException();
}
}
#endregion
-4
View File
@@ -25,10 +25,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Diagnostics;
using System.Globalization;
@@ -0,0 +1,168 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Newtonsoft.Json.Linq
{
internal class JPropertyKeyedCollection : Collection<JToken>
{
private static readonly IEqualityComparer<string> Comparer = StringComparer.Ordinal;
private Dictionary<string, JToken> _dictionary;
private void AddKey(string key, JToken item)
{
EnsureDictionary();
_dictionary[key] = item;
}
protected void ChangeItemKey(JToken item, string newKey)
{
if (!ContainsItem(item))
throw new ArgumentException("The specified item does not exist in this KeyedCollection.");
string keyForItem = GetKeyForItem(item);
if (!Comparer.Equals(keyForItem, newKey))
{
if (newKey != null)
AddKey(newKey, item);
if (keyForItem != null)
RemoveKey(keyForItem);
}
}
protected override void ClearItems()
{
base.ClearItems();
if (_dictionary != null)
_dictionary.Clear();
}
public bool Contains(string key)
{
if (key == null)
throw new ArgumentNullException("key");
if (_dictionary != null)
return _dictionary.ContainsKey(key);
return false;
}
private bool ContainsItem(JToken item)
{
if (_dictionary == null)
return false;
string key = GetKeyForItem(item);
JToken value;
return _dictionary.TryGetValue(key, out value);
}
private void EnsureDictionary()
{
if (_dictionary == null)
_dictionary = new Dictionary<string, JToken>(Comparer);
}
private string GetKeyForItem(JToken item)
{
return ((JProperty)item).Name;
}
protected override void InsertItem(int index, JToken item)
{
AddKey(GetKeyForItem(item), item);
base.InsertItem(index, item);
}
public bool Remove(string key)
{
if (key == null)
throw new ArgumentNullException("key");
if (_dictionary != null)
return _dictionary.ContainsKey(key) && Remove(_dictionary[key]);
return false;
}
protected override void RemoveItem(int index)
{
string keyForItem = GetKeyForItem(Items[index]);
RemoveKey(keyForItem);
base.RemoveItem(index);
}
private void RemoveKey(string key)
{
if (_dictionary != null)
_dictionary.Remove(key);
}
protected override void SetItem(int index, JToken item)
{
string keyForItem = GetKeyForItem(item);
string keyAtIndex = GetKeyForItem(Items[index]);
if (Comparer.Equals(keyAtIndex, keyForItem))
{
if (_dictionary != null)
_dictionary[keyForItem] = item;
}
else
{
AddKey(keyForItem, item);
if (keyAtIndex != null)
RemoveKey(keyAtIndex);
}
base.SetItem(index, item);
}
public JToken this[string key]
{
get
{
if (key == null)
throw new ArgumentNullException("key");
if (_dictionary != null)
return _dictionary[key];
throw new KeyNotFoundException();
}
}
public bool TryGetValue(string key, out JToken value)
{
if (_dictionary == null)
{
value = null;
return false;
}
return _dictionary.TryGetValue(key, out value);
}
public ICollection<string> Keys
{
get
{
EnsureDictionary();
return _dictionary.Keys;
}
}
public ICollection<JToken> Values
{
get
{
EnsureDictionary();
return _dictionary.Values;
}
}
}
}
+1 -5
View File
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Linq
{
+5 -2
View File
@@ -29,13 +29,16 @@ using System.Collections.Generic;
using System.Dynamic;
using System.Linq.Expressions;
#endif
using System.Linq;
using System.IO;
using Newtonsoft.Json.Utilities;
using System.Diagnostics;
using System.Globalization;
using System.Collections;
using System.ComponentModel;
#if NET20
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Linq
{
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
namespace Newtonsoft.Json.Linq
{
-4
View File
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Globalization;
namespace Newtonsoft.Json.Linq
{

Some files were not shown because too many files have changed in this diff Show More