-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
+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