-Upgraded Silverlight project to Silverlight 4

-Included .NET 4 features in Silverlight project
This commit is contained in:
JamesNK
2011-01-03 05:19:57 +00:00
parent 1aa3ff31a1
commit a96f4d4248
18 changed files with 134 additions and 51 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
$builds = @(
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net"; NuGetDir = "40"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.WindowsPhone"; TestsName = $null; Constants="SILVERLIGHT;WINDOWS_PHONE"; FinalDir="WindowsPhone"; NuGetDir = "WP"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Silverlight"; TestsName = "Newtonsoft.Json.Tests.Silverlight"; Constants="SILVERLIGHT"; FinalDir="Silverlight"; NuGetDir = "SL"; Framework="net-2.0"},
@{Name = "Newtonsoft.Json.Silverlight"; TestsName = "Newtonsoft.Json.Tests.Silverlight"; Constants="SILVERLIGHT"; FinalDir="Silverlight"; NuGetDir = "SL"; Framework="net-4.0"},
@{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "35"; Framework="net-2.0"},
@{Name = "Newtonsoft.Json.Net20"; TestsName = "Newtonsoft.Json.Tests.Net20"; Constants="NET20"; FinalDir="Net20"; NuGetDir = "20"; Framework="net-2.0"}
)
+70 -1
View File
@@ -1,6 +1,7 @@
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20)
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
@@ -177,6 +178,74 @@ namespace Newtonsoft.Json.Tests.Linq
T t = d;
Assert.AreEqual(value, t);
}
[Test]
public void DynamicSerializerExample()
{
dynamic value = new DynamicDictionary();
value.Name = "Arine Admin";
value.Enabled = true;
value.Roles = new[] {"Admin", "User"};
string json = JsonConvert.SerializeObject(value, Formatting.Indented);
// {
// "Name": "Arine Admin",
// "Enabled": true,
// "Roles": [
// "Admin",
// "User"
// ]
// }
dynamic newValue = JsonConvert.DeserializeObject<DynamicDictionary>(json);
string role = newValue.Roles[0];
// Admin
}
[Test]
public void DynamicLinqExample()
{
JObject oldAndBusted = new JObject();
oldAndBusted["Name"] = "Arnie Admin";
oldAndBusted["Enabled"] = true;
oldAndBusted["Roles"] = new JArray(new[] { "Admin", "User" });
string oldRole = (string) oldAndBusted["Roles"][0];
// Admin
dynamic newHotness = new JObject();
newHotness.Name = "Arnie Admin";
newHotness.Enabled = true;
newHotness.Roles = new JArray(new[] { "Admin", "User" });
string newRole = newHotness.Roles[0];
// Admin
}
public class DynamicDictionary : DynamicObject
{
private readonly IDictionary<string, object> _values = new Dictionary<string, object>();
public override IEnumerable<string> GetDynamicMemberNames()
{
return _values.Keys;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = _values[binder.Name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_values[binder.Name] = value;
return true;
}
}
}
}
#endif
@@ -14,7 +14,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json.Tests.Silverlight</RootNamespace>
<AssemblyName>Newtonsoft.Json.Tests.Silverlight</AssemblyName>
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightApplication>false</SilverlightApplication>
<FileUpgradeFlags>
</FileUpgradeFlags>
@@ -65,9 +65,16 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\NUnit\Silverlight\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net">
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization">
<Private>True</Private>
@@ -106,6 +113,7 @@
<Compile Include="JsonArrayAttributeTests.cs" />
<Compile Include="Linq\ComponentModel\BindingTests.cs" />
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
<Compile Include="Linq\DynamicTests.cs" />
<Compile Include="Linq\JPathTests.cs" />
<Compile Include="Linq\JRawTests.cs" />
<Compile Include="Linq\JTokenReaderTest.cs" />
@@ -116,6 +124,7 @@
<Compile Include="Schema\JsonSchemaNodeTests.cs" />
<Compile Include="Serialization\CamelCasePropertyNamesContractResolverTests.cs" />
<Compile Include="Serialization\ConstructorHandlingTests.cs" />
<Compile Include="Serialization\DynamicTests.cs" />
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
<Compile Include="Serialization\JsonSerializerTest.cs" />
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
@@ -243,6 +252,7 @@
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Silverlight.csproj">
<Project>{DC3C6F3D-2CA1-4278-9B79-63770FB3EA2D}</Project>
<Name>Newtonsoft.Json.Silverlight</Name>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
@@ -1,4 +1,4 @@
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20)
using System;
using System.Collections;
using System.Collections.Generic;
@@ -147,15 +147,17 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(o, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
});
Console.WriteLine(json);
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Simple);
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full);
string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full);
Assert.AreEqual(@"{
""$type"": ""System.Dynamic.ExpandoObject, System.Core"",
""$type"": """ + expandoObjectTypeName + @""",
""Text"": ""Text!"",
""Integer"": 2147483647,
""DynamicChildObject"": {
@@ -167,7 +169,8 @@ namespace Newtonsoft.Json.Tests.Serialization
dynamic n = JsonConvert.DeserializeObject(json, null, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
});
Assert.IsInstanceOfType(typeof(ExpandoObject), n);
@@ -55,7 +55,7 @@ using System.Text.RegularExpressions;
using System.Collections.Specialized;
using System.Linq.Expressions;
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
#endif
@@ -3753,7 +3753,7 @@ keyword such as type of business.""
}", json);
}
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
[Test]
public void SerializeExpandoObject()
{
@@ -195,7 +195,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(new DateTime(2000, 12, 1, 0, 0, 0, DateTimeKind.Utc), c[2]);
Assert.AreEqual(3, errors.Count);
#if !(NET20 || NET35 || SILVERLIGHT)
#if !(NET20 || NET35 || WINDOWS_PHONE)
Assert.AreEqual("The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.", errors[0]);
#else
Assert.AreEqual("The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.", errors[0]);
@@ -13,8 +13,8 @@ namespace Newtonsoft.Json.Tests
public void SystemVersion()
{
Assembly systemAssembly = typeof(Uri).Assembly;
StringAssert.Contains("=2.0.5.0,", systemAssembly.FullName,
"Check we're testing a Silverlight 2.0 assembly");
StringAssert.Contains("=4.0.0.0,", systemAssembly.FullName,
"Check we're testing a Silverlight 4.0 assembly");
}
}
#endif
+2 -2
View File
@@ -27,7 +27,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
using System.Linq.Expressions;
#endif
@@ -654,7 +654,7 @@ namespace Newtonsoft.Json.Linq
#endregion
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
/// <summary>
/// Returns the <see cref="T:System.Dynamic.DynamicMetaObject"/> responsible for binding operations performed on this object.
/// </summary>
+3 -3
View File
@@ -25,7 +25,7 @@
using System;
using System.Collections.Generic;
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
using System.Linq.Expressions;
#endif
@@ -46,7 +46,7 @@ namespace Newtonsoft.Json.Linq
#if !SILVERLIGHT
, ICloneable
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
, IDynamicMetaObjectProvider
#endif
{
@@ -1276,7 +1276,7 @@ namespace Newtonsoft.Json.Linq
return p.Evaluate(this, errorWhenNoMatch);
}
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
/// <summary>
/// Returns the <see cref="T:System.Dynamic.DynamicMetaObject"/> responsible for binding operations performed on this object.
/// </summary>
+3 -12
View File
@@ -30,7 +30,7 @@ using System.Text;
using Newtonsoft.Json.Utilities;
using System.Globalization;
using System.ComponentModel;
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
using System.Linq.Expressions;
#endif
@@ -406,7 +406,7 @@ namespace Newtonsoft.Json.Linq
return _value.GetHashCode();
}
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
/// <summary>
/// Returns the <see cref="T:System.Dynamic.DynamicMetaObject"/> responsible for binding operations performed on this object.
/// </summary>
@@ -437,16 +437,7 @@ namespace Newtonsoft.Json.Linq
return ReflectionUtils.IsNullable(binder.Type);
}
Type t = binder.Type;
if (ReflectionUtils.IsNullableType(t))
t = Nullable.GetUnderlyingType(t);
TypeConverter converter = TypeDescriptor.GetConverter(instance.Value);
if (converter != null && converter.CanConvertTo(t))
result = converter.ConvertTo(instance.Value, t);
else
result = Convert.ChangeType(instance.Value, t, CultureInfo.InvariantCulture);
result = ConvertUtils.Convert(instance.Value, CultureInfo.InvariantCulture, binder.Type);
return true;
}
}
@@ -14,7 +14,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json</RootNamespace>
<AssemblyName>Newtonsoft.Json.Silverlight</AssemblyName>
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>false</ThrowErrorsInValidation>
@@ -191,7 +191,10 @@
<Compile Include="Utilities\ConvertUtils.cs" />
<Compile Include="Utilities\DateTimeUtils.cs" />
<Compile Include="Utilities\DictionaryWrapper.cs" />
<Compile Include="Utilities\DynamicProxy.cs" />
<Compile Include="Utilities\DynamicProxyMetaObject.cs" />
<Compile Include="Utilities\DynamicReflectionDelegateFactory.cs" />
<Compile Include="Utilities\DynamicUtils.cs" />
<Compile Include="Utilities\DynamicWrapper.cs" />
<Compile Include="Utilities\EnumUtils.cs" />
<Compile Include="Utilities\EnumValue.cs" />
@@ -27,7 +27,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
#endif
using System.Globalization;
@@ -86,8 +86,10 @@ namespace Newtonsoft.Json.Serialization
#endif
new BinaryConverter(),
new KeyValuePairConverter(),
#if !SILVERLIGHT
#if !SILVERLIGHT || WINDOWS_PHONE
new XmlNodeConverter(),
#endif
#if !SILVERLIGHT
new DataSetConverter(),
new DataTableConverter(),
#endif
@@ -450,7 +452,7 @@ namespace Newtonsoft.Json.Serialization
}
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
/// <summary>
/// Creates a <see cref="JsonDynamicContract"/> for the given type.
/// </summary>
@@ -515,7 +517,7 @@ namespace Newtonsoft.Json.Serialization
return CreateISerializableContract(t);
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(t))
return CreateDynamicContract(t);
#endif
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -27,7 +27,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
#endif
using System.Globalization;
@@ -406,7 +406,7 @@ namespace Newtonsoft.Json.Serialization
}
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
JsonDynamicContract dynamicContract = contract as JsonDynamicContract;
if (dynamicContract != null)
{
@@ -456,7 +456,11 @@ namespace Newtonsoft.Json.Serialization
private bool HasDefinedType(Type type)
{
return (type != null && type != typeof (object) && !type.IsSubclassOf(typeof(JToken)));
return (type != null && type != typeof (object) && !typeof(JToken).IsAssignableFrom(type)
#if !(NET35 || NET20 || WINDOWS_PHONE)
&& type != typeof(IDynamicMetaObjectProvider)
#endif
);
}
private object EnsureType(object value, Type targetType)
@@ -762,7 +766,7 @@ namespace Newtonsoft.Json.Serialization
}
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
private object CreateDynamic(JsonReader reader, JsonDynamicContract contract, string id)
{
IDynamicMetaObjectProvider newObject = null;
@@ -799,9 +803,9 @@ namespace Newtonsoft.Json.Serialization
}
else
{
object value = (JsonReader.IsPrimitiveToken(reader.TokenType))
? reader.Value
: CreateObject(reader, typeof(IDynamicMetaObjectProvider), GetContractSafe(typeof(IDynamicMetaObjectProvider), null), null, null);
Type t = (JsonReader.IsPrimitiveToken(reader.TokenType)) ? reader.ValueType : typeof (IDynamicMetaObjectProvider);
object value = CreateValueNonProperty(reader, t, GetContractSafe(t, null));
newObject.TrySetMember(memberName, value);
}
@@ -27,7 +27,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System.Dynamic;
#endif
using System.Globalization;
@@ -136,7 +136,7 @@ namespace Newtonsoft.Json.Serialization
SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract);
}
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
else if (valueContract is JsonDynamicContract)
{
SerializeDynamic(writer, (IDynamicMetaObjectProvider)value, (JsonDynamicContract)valueContract);
@@ -474,7 +474,7 @@ namespace Newtonsoft.Json.Serialization
}
#endif
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract)
{
contract.InvokeOnSerializing(value, Serializer.Context);
@@ -1,4 +1,4 @@
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System;
using System.Collections.Generic;
using System.Dynamic;
@@ -1,4 +1,4 @@
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System;
using System.Collections.Generic;
using System.Dynamic;
@@ -1,4 +1,4 @@
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || WINDOWS_PHONE)
using System;
using System.Collections.Generic;
using System.Dynamic;
@@ -8,6 +8,7 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Globalization;
using Newtonsoft.Json.Serialization;
namespace Newtonsoft.Json.Utilities
{
@@ -70,10 +71,10 @@ namespace Newtonsoft.Json.Utilities
Type csharpArgumentInfoTypeEnumerableType = typeof(IEnumerable<>).MakeGenericType(csharpArgumentInfoType);
MethodInfo getMemberMethod = binderType.GetMethod("GetMember", BindingFlags.Public | BindingFlags.Static, null, new[] { csharpBinderFlagsType, typeof(string), typeof(Type), csharpArgumentInfoTypeEnumerableType }, null);
_getMemberCall = DynamicReflectionDelegateFactory.Instance.CreateMethodCall<object>(getMemberMethod);
_getMemberCall = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(getMemberMethod);
MethodInfo setMemberMethod = binderType.GetMethod("SetMember", BindingFlags.Public | BindingFlags.Static, null, new[] { csharpBinderFlagsType, typeof(string), typeof(Type), csharpArgumentInfoTypeEnumerableType }, null);
_setMemberCall = DynamicReflectionDelegateFactory.Instance.CreateMethodCall<object>(setMemberMethod);
_setMemberCall = JsonTypeReflector.ReflectionDelegateFactory.CreateMethodCall<object>(setMemberMethod);
}
public static CallSiteBinder GetMember(string name, Type context)