diff options
author | JamesNK <james@newtonking.com> | 2010-09-12 02:56:13 +0400 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2010-09-12 02:56:13 +0400 |
commit | 11ce71ee8b72a0892cbfdfa22d5343e0dffa7fa8 (patch) | |
tree | f321b84eb50a34943963bdc2bf77556eda8ca5db /Src | |
parent | 43501484fbf58864fab17cc975afe60760113725 (diff) |
-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
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs | 5 | ||||
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs | 20 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/JsonValidatingReader.cs | 11 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JContainer.cs | 27 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JObject.cs | 9 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj | 3 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Newtonsoft.Json.csproj | 3 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Properties/AssemblyInfo.cs | 5 |
8 files changed, 57 insertions, 26 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs index dc1264e..73e433b 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs @@ -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");
diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs index d2538de..92e52e7 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs @@ -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]);
+ }
}
}
\ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonValidatingReader.cs b/Src/Newtonsoft.Json/JsonValidatingReader.cs index 23a1cd4..4a46a90 100644 --- a/Src/Newtonsoft.Json/JsonValidatingReader.cs +++ b/Src/Newtonsoft.Json/JsonValidatingReader.cs @@ -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;
}
diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index 52d2a78..b9704a3 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -48,6 +48,9 @@ namespace Newtonsoft.Json.Linq #else
, IList, INotifyCollectionChanged
#endif
+#if !(SILVERLIGHT || NET20 || NET35)
+ , INotifyCollectionChanged
+#endif
{
#if !SILVERLIGHT
/// <summary>
@@ -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
}
diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 957e1f6..308f2db 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -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
}
diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index 5edb4bc..585b88a 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -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>
diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index 153a3e8..7c6902d 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -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>
diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index df6333d..8862465 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -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
|