-Added INotifyCollectionChanged to JContainer in .NET 4.0 build
-Changed .NET 3.5 and .NET 4.0 builds to target client frameworks -Fixed JSON Schema not raising an error for additional properties when the schema has no properties
This commit is contained in:
@@ -1305,9 +1305,10 @@ Parameter name: arrayIndex")]
|
|||||||
Assert.AreEqual(index, 0);
|
Assert.AreEqual(index, 0);
|
||||||
Assert.AreEqual(2, (int)o["Test1"]);
|
Assert.AreEqual(2, (int)o["Test1"]);
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
[Test]
|
[Test]
|
||||||
public void ListChanged()
|
public void CollectionChanged()
|
||||||
{
|
{
|
||||||
JProperty p1 = new JProperty("Test1", 1);
|
JProperty p1 = new JProperty("Test1", 1);
|
||||||
JProperty p2 = new JProperty("Test2", "Two");
|
JProperty p2 = new JProperty("Test2", "Two");
|
||||||
|
|||||||
@@ -197,5 +197,25 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
GenerateSchemaAndSerializeFromType(DBNull.Value);
|
GenerateSchemaAndSerializeFromType(DBNull.Value);
|
||||||
GenerateSchemaAndSerializeFromType(new JsonPropertyWithHandlingValues());
|
GenerateSchemaAndSerializeFromType(new JsonPropertyWithHandlingValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UndefinedPropertyOnNoPropertySchema()
|
||||||
|
{
|
||||||
|
JsonSchema schema = JsonSchema.Parse(@"{
|
||||||
|
""description"": ""test"",
|
||||||
|
""type"": ""object"",
|
||||||
|
""additionalProperties"": false,
|
||||||
|
""properties"": {
|
||||||
|
}
|
||||||
|
}");
|
||||||
|
|
||||||
|
JObject o = JObject.Parse("{'g':1}");
|
||||||
|
|
||||||
|
List<string> errors = new List<string>();
|
||||||
|
o.Validate(schema, (sender, args) => errors.Add(args.Message));
|
||||||
|
|
||||||
|
Assert.AreEqual(1, errors.Count);
|
||||||
|
Assert.AreEqual("Property 'g' has not been defined and the schema does not allow additional properties. Line 1, position 5.", errors[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,15 +552,10 @@ namespace Newtonsoft.Json
|
|||||||
if (_currentScope.RequiredProperties.ContainsKey(propertyName))
|
if (_currentScope.RequiredProperties.ContainsKey(propertyName))
|
||||||
_currentScope.RequiredProperties[propertyName] = true;
|
_currentScope.RequiredProperties[propertyName] = true;
|
||||||
|
|
||||||
if (schema.Properties != null && !schema.Properties.ContainsKey(propertyName))
|
bool propertyDefinied = (schema.Properties != null && schema.Properties.ContainsKey(propertyName));
|
||||||
{
|
|
||||||
IList<string> definedProperties = schema.Properties.Select(p => p.Key).ToList();
|
|
||||||
|
|
||||||
if (!schema.AllowAdditionalProperties && !definedProperties.Contains(propertyName))
|
if (!propertyDefinied && !schema.AllowAdditionalProperties)
|
||||||
{
|
RaiseError("Property '{0}' has not been defined and the schema does not allow additional properties.".FormatWith(CultureInfo.InvariantCulture, propertyName), schema);
|
||||||
RaiseError("Property '{0}' has not been defined and the schema does not allow additional properties.".FormatWith(CultureInfo.InvariantCulture, propertyName), schema);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentScope.CurrentPropertyName = propertyName;
|
_currentScope.CurrentPropertyName = propertyName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ namespace Newtonsoft.Json.Linq
|
|||||||
, ITypedList, IBindingList
|
, ITypedList, IBindingList
|
||||||
#else
|
#else
|
||||||
, IList, INotifyCollectionChanged
|
, IList, INotifyCollectionChanged
|
||||||
|
#endif
|
||||||
|
#if !(SILVERLIGHT || NET20 || NET35)
|
||||||
|
, INotifyCollectionChanged
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
@@ -59,7 +62,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// Occurs before an item is added to the collection.
|
/// Occurs before an item is added to the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event AddingNewEventHandler AddingNew;
|
public event AddingNewEventHandler AddingNew;
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when the items list of the collection has changed, or the collection is reset.
|
/// Occurs when the items list of the collection has changed, or the collection is reset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -135,7 +139,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raises the <see cref="CollectionChanged"/> event.
|
/// Raises the <see cref="CollectionChanged"/> event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -309,7 +314,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
if (ListChanged != null)
|
if (ListChanged != null)
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, IndexOfItem(item)));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, IndexOfItem(item)));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
if (CollectionChanged != null)
|
if (CollectionChanged != null)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, IndexOfItem(item)));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, IndexOfItem(item)));
|
||||||
#endif
|
#endif
|
||||||
@@ -401,7 +407,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, token, index));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, token, index));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -447,7 +454,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, itemIndex));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, itemIndex));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, itemIndex));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, itemIndex));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -468,7 +476,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, item, token, index));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, item, token, index));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -496,7 +505,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -547,7 +557,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
|
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, itemIndex));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, itemIndex));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, replacement, existing, itemIndex));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, replacement, existing, itemIndex));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// Represents a JSON object.
|
/// Represents a JSON object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JObject : JContainer, IDictionary<string, JToken>, INotifyPropertyChanged
|
public class JObject : JContainer, IDictionary<string, JToken>, INotifyPropertyChanged
|
||||||
#if !PocketPC && !SILVERLIGHT
|
#if !(PocketPC || SILVERLIGHT)
|
||||||
, ICustomTypeDescriptor
|
, ICustomTypeDescriptor
|
||||||
#endif
|
#endif
|
||||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
#if !(PocketPC || SILVERLIGHT || NET20)
|
||||||
, INotifyPropertyChanging
|
, INotifyPropertyChanging
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
#if !(PocketPC || SILVERLIGHT || NET20)
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when a property value is changing.
|
/// Occurs when a property value is changing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -126,7 +126,8 @@ namespace Newtonsoft.Json.Linq
|
|||||||
OnPropertyChanged(childProperty.Name);
|
OnPropertyChanged(childProperty.Name);
|
||||||
#if !SILVERLIGHT
|
#if !SILVERLIGHT
|
||||||
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, IndexOfItem(childProperty)));
|
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, IndexOfItem(childProperty)));
|
||||||
#else
|
#endif
|
||||||
|
#if SILVERLIGHT || !(NET20 || NET35)
|
||||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, childProperty, childProperty, IndexOfItem(childProperty)));
|
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, childProperty, childProperty, IndexOfItem(childProperty)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,7 @@
|
|||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
<TargetFrameworkProfile>
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
</TargetFrameworkProfile>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|||||||
@@ -42,8 +42,7 @@
|
|||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
<TargetFrameworkProfile>
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
</TargetFrameworkProfile>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ using System.Security;
|
|||||||
#elif NET20
|
#elif NET20
|
||||||
[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 2.0")]
|
[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 2.0")]
|
||||||
[assembly: AllowPartiallyTrustedCallers]
|
[assembly: AllowPartiallyTrustedCallers]
|
||||||
|
#elif NET35
|
||||||
|
[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 3.5")]
|
||||||
|
[assembly: AllowPartiallyTrustedCallers]
|
||||||
#else
|
#else
|
||||||
[assembly: AssemblyTitle("Newtonsoft Json.NET")]
|
[assembly: AssemblyTitle("Newtonsoft Json.NET")]
|
||||||
[assembly: AllowPartiallyTrustedCallers]
|
[assembly: AllowPartiallyTrustedCallers]
|
||||||
@@ -60,6 +63,8 @@ using System.Security;
|
|||||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Compact, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Compact, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
||||||
#elif NET20
|
#elif NET20
|
||||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Net20, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Net20, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
||||||
|
#elif NET35
|
||||||
|
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Net35, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
||||||
#else
|
#else
|
||||||
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user