-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:
JamesNK
2010-09-11 22:56:13 +00:00
parent 43501484fb
commit 11ce71ee8b
8 changed files with 57 additions and 26 deletions
@@ -1305,9 +1305,10 @@ Parameter name: arrayIndex")]
Assert.AreEqual(index, 0);
Assert.AreEqual(2, (int)o["Test1"]);
}
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
[Test]
public void ListChanged()
public void CollectionChanged()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
@@ -197,5 +197,25 @@ namespace Newtonsoft.Json.Tests.Schema
GenerateSchemaAndSerializeFromType(DBNull.Value);
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]);
}
}
}
+3 -8
View File
@@ -552,15 +552,10 @@ namespace Newtonsoft.Json
if (_currentScope.RequiredProperties.ContainsKey(propertyName))
_currentScope.RequiredProperties[propertyName] = true;
if (schema.Properties != null && !schema.Properties.ContainsKey(propertyName))
{
IList<string> definedProperties = schema.Properties.Select(p => p.Key).ToList();
bool propertyDefinied = (schema.Properties != null && schema.Properties.ContainsKey(propertyName));
if (!schema.AllowAdditionalProperties && !definedProperties.Contains(propertyName))
{
RaiseError("Property '{0}' has not been defined and the schema does not allow additional properties.".FormatWith(CultureInfo.InvariantCulture, propertyName), schema);
}
}
if (!propertyDefinied && !schema.AllowAdditionalProperties)
RaiseError("Property '{0}' has not been defined and the schema does not allow additional properties.".FormatWith(CultureInfo.InvariantCulture, propertyName), schema);
_currentScope.CurrentPropertyName = propertyName;
}
+19 -8
View File
@@ -47,6 +47,9 @@ namespace Newtonsoft.Json.Linq
, ITypedList, IBindingList
#else
, IList, INotifyCollectionChanged
#endif
#if !(SILVERLIGHT || NET20 || NET35)
, INotifyCollectionChanged
#endif
{
#if !SILVERLIGHT
@@ -59,7 +62,8 @@ namespace Newtonsoft.Json.Linq
/// Occurs before an item is added to the collection.
/// </summary>
public event AddingNewEventHandler AddingNew;
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
/// <summary>
/// Occurs when the items list of the collection has changed, or the collection is reset.
/// </summary>
@@ -135,7 +139,8 @@ namespace Newtonsoft.Json.Linq
}
}
}
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
/// <summary>
/// Raises the <see cref="CollectionChanged"/> event.
/// </summary>
@@ -309,7 +314,8 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
if (ListChanged != null)
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, IndexOfItem(item)));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
if (CollectionChanged != null)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, IndexOfItem(item)));
#endif
@@ -401,7 +407,8 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, token, index));
#endif
@@ -447,7 +454,8 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, itemIndex));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, itemIndex));
#endif
@@ -468,7 +476,8 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, item, token, index));
#endif
}
@@ -496,7 +505,8 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
#endif
}
@@ -547,7 +557,8 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, itemIndex));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, replacement, existing, itemIndex));
#endif
}
+5 -4
View File
@@ -45,10 +45,10 @@ namespace Newtonsoft.Json.Linq
/// Represents a JSON object.
/// </summary>
public class JObject : JContainer, IDictionary<string, JToken>, INotifyPropertyChanged
#if !PocketPC && !SILVERLIGHT
#if !(PocketPC || SILVERLIGHT)
, ICustomTypeDescriptor
#endif
#if !PocketPC && !SILVERLIGHT && !NET20
#if !(PocketPC || SILVERLIGHT || NET20)
, INotifyPropertyChanging
#endif
{
@@ -57,7 +57,7 @@ namespace Newtonsoft.Json.Linq
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#if !PocketPC && !SILVERLIGHT && !NET20
#if !(PocketPC || SILVERLIGHT || NET20)
/// <summary>
/// Occurs when a property value is changing.
/// </summary>
@@ -126,7 +126,8 @@ namespace Newtonsoft.Json.Linq
OnPropertyChanged(childProperty.Name);
#if !SILVERLIGHT
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, IndexOfItem(childProperty)));
#else
#endif
#if SILVERLIGHT || !(NET20 || NET35)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, childProperty, childProperty, IndexOfItem(childProperty)));
#endif
}
@@ -42,8 +42,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
+1 -2
View File
@@ -42,8 +42,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -33,6 +33,9 @@ using System.Security;
#elif NET20
[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 2.0")]
[assembly: AllowPartiallyTrustedCallers]
#elif NET35
[assembly: AssemblyTitle("Newtonsoft Json.NET .NET 3.5")]
[assembly: AllowPartiallyTrustedCallers]
#else
[assembly: AssemblyTitle("Newtonsoft Json.NET")]
[assembly: AllowPartiallyTrustedCallers]
@@ -60,6 +63,8 @@ using System.Security;
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Compact, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
#elif NET20
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Net20, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
#elif NET35
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Net35, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
#else
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
#endif