-Added .NET 3.5 build
-Added dynamic support to LINQ to JSON -Added dynamic support to serializer
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
#if !(NET35 || NET20 || SILVERLIGHT)
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Linq
|
||||
{
|
||||
public class DynamicTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void JObjectPropertyNames()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("ChildValue", "blah blah"));
|
||||
|
||||
dynamic d = o;
|
||||
|
||||
d.First = "A value!";
|
||||
|
||||
Assert.AreEqual(new JValue("A value!"), d.First);
|
||||
Assert.AreEqual("A value!", (string)d.First);
|
||||
|
||||
d.First = null;
|
||||
Assert.AreEqual(JTokenType.Null, d.First.Type);
|
||||
|
||||
Assert.IsTrue(d.Remove("First"));
|
||||
Assert.IsNull(d.First);
|
||||
|
||||
JValue v1 = d.ChildValue;
|
||||
JValue v2 = d["ChildValue"];
|
||||
Assert.AreEqual(v1, v2);
|
||||
|
||||
JValue newValue1 = new JValue("Blah blah");
|
||||
d.NewValue = newValue1;
|
||||
JValue newValue2 = d.NewValue;
|
||||
|
||||
Assert.IsTrue(ReferenceEquals(newValue1, newValue2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectEnumerator()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("ChildValue", "blah blah"));
|
||||
|
||||
dynamic d = o;
|
||||
|
||||
foreach (JProperty value in d)
|
||||
{
|
||||
Assert.AreEqual("ChildValue", value.Name);
|
||||
Assert.AreEqual("blah blah", (string)value.Value);
|
||||
}
|
||||
|
||||
foreach (dynamic value in d)
|
||||
{
|
||||
Assert.AreEqual("ChildValue", value.Name);
|
||||
Assert.AreEqual("blah blah", (string)value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectPropertyNameWithJArray()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("ChildValue", "blah blah"));
|
||||
|
||||
dynamic d = o;
|
||||
|
||||
d.First = new JArray();
|
||||
d.First.Add("Hi");
|
||||
|
||||
Assert.AreEqual(1, d.First.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Could not determine JSON object type for type System.String[].")]
|
||||
public void JObjectPropertyNameWithNonToken()
|
||||
{
|
||||
dynamic d = new JObject();
|
||||
|
||||
d.First = new [] {"One", "II", "3"};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectMethods()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("ChildValue", "blah blah"));
|
||||
|
||||
dynamic d = o;
|
||||
|
||||
d.Add("NewValue", 1);
|
||||
|
||||
object count = d.Count;
|
||||
|
||||
Assert.IsNull(count);
|
||||
Assert.IsNull(d["Count"]);
|
||||
|
||||
JToken v;
|
||||
Assert.IsTrue(d.TryGetValue("ChildValue", out v));
|
||||
Assert.AreEqual("blah blah", (string)v);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectGetDynamicPropertyNames()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("ChildValue", "blah blah"),
|
||||
new JProperty("Hello Joe", null));
|
||||
|
||||
dynamic d = o;
|
||||
|
||||
List<string> memberNames = o.GetDynamicMemberNames().ToList();
|
||||
|
||||
Assert.AreEqual(2, memberNames.Count);
|
||||
Assert.AreEqual("ChildValue", memberNames[0]);
|
||||
Assert.AreEqual("Hello Joe", memberNames[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JValueConvert()
|
||||
{
|
||||
AssertValueConverted<bool>(true);
|
||||
AssertValueConverted<bool?>(true);
|
||||
AssertValueConverted<byte[]>(Encoding.UTF8.GetBytes("blah"));
|
||||
AssertValueConverted<DateTime>(new DateTime(2000, 12, 20, 23, 59, 2, DateTimeKind.Utc));
|
||||
AssertValueConverted<DateTime?>(new DateTime(2000, 12, 20, 23, 59, 2, DateTimeKind.Utc));
|
||||
AssertValueConverted<DateTimeOffset>(new DateTimeOffset(2000, 12, 20, 23, 59, 2, TimeSpan.FromHours(1)));
|
||||
AssertValueConverted<DateTimeOffset?>(new DateTimeOffset(2000, 12, 20, 23, 59, 2, TimeSpan.FromHours(1)));
|
||||
AssertValueConverted<decimal>(99.9m);
|
||||
AssertValueConverted<decimal?>(99.9m);
|
||||
AssertValueConverted<double>(99.9);
|
||||
AssertValueConverted<double?>(99.9);
|
||||
AssertValueConverted<float>(99.9f);
|
||||
AssertValueConverted<float?>(99.9f);
|
||||
AssertValueConverted<int>(int.MinValue);
|
||||
AssertValueConverted<int?>(int.MinValue);
|
||||
AssertValueConverted<long>(long.MaxValue);
|
||||
AssertValueConverted<long?>(long.MaxValue);
|
||||
AssertValueConverted<short>(short.MaxValue);
|
||||
AssertValueConverted<short?>(short.MaxValue);
|
||||
AssertValueConverted<string>("blah");
|
||||
AssertValueConverted<uint>(uint.MinValue);
|
||||
AssertValueConverted<uint?>(uint.MinValue);
|
||||
AssertValueConverted<ulong>(ulong.MaxValue);
|
||||
AssertValueConverted<ulong?>(ulong.MaxValue);
|
||||
AssertValueConverted<ushort>(ushort.MinValue);
|
||||
AssertValueConverted<ushort?>(ushort.MinValue);
|
||||
}
|
||||
|
||||
private static void AssertValueConverted<T>(T value)
|
||||
{
|
||||
JValue v = new JValue(value);
|
||||
dynamic d = v;
|
||||
|
||||
Assert.AreEqual(value, (T)d);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Database Class="LinqToSqlClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
|
||||
<?xml version="1.0" encoding="utf-8"?><Database EntityNamespace="Newtonsoft.Json.Tests.LinqToSql" ContextNamespace="Newtonsoft.Json.Tests.LinqToSql" Class="LinqToSqlClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
|
||||
<Table Name="" Member="Persons">
|
||||
<Type Name="Person">
|
||||
<Column Name="FirstName" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="LastName" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="PersonId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Column Member="DepartmentId" Type="System.Guid" CanBeNull="false" />
|
||||
<Column Name="DepartmentId" Type="System.Guid" CanBeNull="false" />
|
||||
<Association Name="Person_PersonRole" Member="PersonRoles" ThisKey="PersonId" OtherKey="PersonId" Type="PersonRole" />
|
||||
<Association Name="Department_Person" Member="Department" ThisKey="DepartmentId" OtherKey="DepartmentId" Type="Department" IsForeignKey="true" />
|
||||
</Type>
|
||||
@@ -29,7 +28,7 @@
|
||||
<Table Name="" Member="Departments">
|
||||
<Type Name="Department">
|
||||
<Column Name="DepartmentId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Column Member="Name" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="Name" Type="System.String" CanBeNull="false" />
|
||||
<Association Name="Department_Person" Member="Persons" ThisKey="DepartmentId" OtherKey="DepartmentId" Type="Person" />
|
||||
</Type>
|
||||
</Table>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<elementListCompartment Id="6865be45-c748-47ff-be37-534064fc2e80" absoluteBounds="3.7649999999999997, 2.71, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<associationConnector edgePoints="[(2.875 : 2.85179768880208); (3.75 : 2.85179768880208)]" fixedFrom="Algorithm" fixedTo="Algorithm">
|
||||
<associationConnector edgePoints="[(2.875 : 2.85179768880208); (3.75 : 2.85179768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Person/Person_PersonRole" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="be91ec15-4a64-4976-9358-2e01309ef584" />
|
||||
@@ -40,7 +40,7 @@
|
||||
<elementListCompartment Id="46cdd558-04c5-4c77-82ce-fe92cda427fe" absoluteBounds="0.89, 4.96, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<associationConnector edgePoints="[(1.875 : 4.5); (1.875 : 3.45359537760417)]" fixedFrom="Algorithm" fixedTo="Algorithm">
|
||||
<associationConnector edgePoints="[(1.875 : 4.5); (1.875 : 3.45359537760417)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Department/Department_Person" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="b96fa86b-7f23-489f-8eb2-44ca2af1551b" />
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{3E6E2335-B079-4B5B-A65A-9D586914BCBB}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Newtonsoft.Json.Tests.Net35</RootNamespace>
|
||||
<AssemblyName>Newtonsoft.Json.Tests.Net35</AssemblyName>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
<SccLocalPath>
|
||||
</SccLocalPath>
|
||||
<SccAuxPath>
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\DotNet35\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NET35</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\DotNet35\</OutputPath>
|
||||
<DefineConstants>TRACE;NET35</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\NUnit\DotNet\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.Entity">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Serialization">
|
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.ServiceModel">
|
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.ServiceModel.Web">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Bson\BsonWriterTests.cs" />
|
||||
<Compile Include="Bson\BsonReaderTests.cs" />
|
||||
<Compile Include="Converters\BinaryConverterTests.cs" />
|
||||
<Compile Include="Converters\RegexConverterTests.cs" />
|
||||
<Compile Include="Converters\DataTableConverterTests.cs" />
|
||||
<Compile Include="Converters\DataSetConverterTests.cs" />
|
||||
<Compile Include="Converters\CustomCreationConverterTests.cs" />
|
||||
<Compile Include="Converters\ObjectIdConverterTests.cs" />
|
||||
<Compile Include="Converters\StringEnumConverterTests.cs" />
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="LinqToSql\Department.cs" />
|
||||
<Compile Include="LinqToSql\DepartmentConverter.cs" />
|
||||
<Compile Include="LinqToSql\GuidByteArrayConverter.cs" />
|
||||
<Compile Include="LinqToSql\Role.cs" />
|
||||
<Compile Include="LinqToSql\LinqToSqlClasses.designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>LinqToSqlClasses.dbml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="LinqToSql\LinqToSqlClassesSerializationTests.cs" />
|
||||
<Compile Include="LinqToSql\Person.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="Serialization\ConstructorHandlingTests.cs" />
|
||||
<Compile Include="Serialization\ContractResolverTests.cs" />
|
||||
<Compile Include="Serialization\DefaultValueHandlingTests.cs" />
|
||||
<Compile Include="Serialization\DynamicTests.cs" />
|
||||
<Compile Include="Serialization\NullValueHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\Bar.cs" />
|
||||
<Compile Include="TestObjects\Car.cs" />
|
||||
<Compile Include="TestObjects\Computer.cs" />
|
||||
<Compile Include="TestObjects\ConstructorReadonlyFields.cs" />
|
||||
<Compile Include="TestObjects\Container.cs" />
|
||||
<Compile Include="TestObjects\ContentBaseClass.cs" />
|
||||
<Compile Include="TestObjects\ContentSubClass.cs" />
|
||||
<Compile Include="TestObjects\Foo.cs" />
|
||||
<Compile Include="TestObjects\HolderClass.cs" />
|
||||
<Compile Include="TestObjects\ListOfIds.cs" />
|
||||
<Compile Include="TestObjects\Movie.cs" />
|
||||
<Compile Include="TestObjects\PersonError.cs" />
|
||||
<Compile Include="TestObjects\PersonPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
|
||||
<Compile Include="TestObjects\DictionaryInterfaceClass.cs" />
|
||||
<Compile Include="TestObjects\Event.cs" />
|
||||
<Compile Include="TestObjects\GoogleMapGeocoderStructure.cs" />
|
||||
<Compile Include="TestObjects\InterfacePropertyTestClass.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObject.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObjectCollection.cs" />
|
||||
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
|
||||
<Compile Include="Serialization\PopulateTests.cs" />
|
||||
<Compile Include="Serialization\SerializationErrorHandlingTests.cs" />
|
||||
<Compile Include="Serialization\SerializationEventAttributeTests.cs" />
|
||||
<Compile Include="Schema\ExtensionsTests.cs" />
|
||||
<Compile Include="Schema\JsonSchemaModelBuilderTests.cs" />
|
||||
<Compile Include="Schema\JsonSchemaNodeTests.cs" />
|
||||
<Compile Include="Serialization\CamelCasePropertyNamesContractResolverTests.cs" />
|
||||
<Compile Include="Serialization\PreserveReferencesHandlingTests.cs" />
|
||||
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\ListTestClass.cs" />
|
||||
<Compile Include="TestObjects\LogEntry.cs" />
|
||||
<Compile Include="TestObjects\NonRequest.cs" />
|
||||
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
|
||||
<Compile Include="TestObjects\SearchResult.cs" />
|
||||
<Compile Include="TestObjects\StructTest.cs" />
|
||||
<Compile Include="TestObjects\WagePerson.cs" />
|
||||
<Compile Include="TestObjects\PropertyCase.cs" />
|
||||
<Compile Include="TestObjects\RequestOnly.cs" />
|
||||
<Compile Include="TestObjects\RoleTransfer.cs" />
|
||||
<Compile Include="TestObjects\SetOnlyPropertyClass2.cs" />
|
||||
<Compile Include="TestObjects\SubKlass.cs" />
|
||||
<Compile Include="TestObjects\SuperKlass.cs" />
|
||||
<Compile Include="TestObjects\VersionKeyedCollection.cs" />
|
||||
<Compile Include="TestObjects\AbstractGenericBase.cs" />
|
||||
<Compile Include="TestObjects\ArgumentConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\BadJsonPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\CircularReferenceClass.cs" />
|
||||
<Compile Include="TestObjects\ClassAndMemberConverterClass.cs" />
|
||||
<Compile Include="TestObjects\ClassConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\ConstructorCaseSensitivityClass.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClass.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\CircularReferenceWithIdClass.cs" />
|
||||
<Compile Include="TestObjects\EmployeeReference.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyWithHandlingValues.cs" />
|
||||
<Compile Include="TestObjects\DefaultValueAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\DoubleClass.cs" />
|
||||
<Compile Include="TestObjects\GenericImpl.cs" />
|
||||
<Compile Include="TestObjects\GenericListAndDictionaryInterfaceProperties.cs" />
|
||||
<Compile Include="TestObjects\GetOnlyPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\IncompatibleJsonAttributeClass.cs" />
|
||||
<Compile Include="TestObjects\Invoice.cs" />
|
||||
<Compile Include="TestObjects\JsonIgnoreAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\MemberConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\MethodExecutorObject.cs" />
|
||||
<Compile Include="TestObjects\JaggedArray.cs" />
|
||||
<Compile Include="TestObjects\MyClass.cs" />
|
||||
<Compile Include="TestObjects\Name.cs" />
|
||||
<Compile Include="TestObjects\PersonRaw.cs" />
|
||||
<Compile Include="TestObjects\PhoneNumber.cs" />
|
||||
<Compile Include="TestObjects\PrivateMembersClass.cs" />
|
||||
<Compile Include="TestObjects\RequiredMembersClass.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestDictionary.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestList.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestObject.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestObjectWithConstructor.cs" />
|
||||
<Compile Include="TestObjects\SetOnlyPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\Article.cs" />
|
||||
<Compile Include="TestObjects\ArticleCollection.cs" />
|
||||
<Compile Include="TestObjects\ClassWithArray.cs" />
|
||||
<Compile Include="TestObjects\ClassWithGuid.cs" />
|
||||
<Compile Include="TestObjects\ConverableMembers.cs" />
|
||||
<Compile Include="TestObjects\JsonIgnoreAttributeOnClassTestClass.cs" />
|
||||
<Compile Include="Linq\JConstructorTests.cs" />
|
||||
<Compile Include="Linq\JPropertyTests.cs" />
|
||||
<Compile Include="TestObjects\MemberConverterClass.cs" />
|
||||
<Compile Include="TestObjects\Product.cs" />
|
||||
<Compile Include="TestObjects\ProductCollection.cs" />
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\Shortie.cs" />
|
||||
<Compile Include="TestObjects\Store.cs" />
|
||||
<Compile Include="TestObjects\StoreColor.cs" />
|
||||
<Compile Include="TestObjects\Person.cs" />
|
||||
<Compile Include="Schema\JsonSchemaBuilderTests.cs" />
|
||||
<Compile Include="Schema\JsonSchemaGeneratorTests.cs" />
|
||||
<Compile Include="Schema\JsonSchemaTests.cs" />
|
||||
<Compile Include="TestObjects\NullableDateTimeTestClass.cs" />
|
||||
<Compile Include="TestObjects\DateTimeTestClass.cs" />
|
||||
<Compile Include="Converters\IsoDateTimeConverterTests.cs" />
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||
<Compile Include="Linq\JTokenWriterTest.cs" />
|
||||
<Compile Include="Linq\JArrayTests.cs" />
|
||||
<Compile Include="Linq\JObjectTests.cs" />
|
||||
<Compile Include="Linq\JTokenEqualityComparerTests.cs" />
|
||||
<Compile Include="Linq\JTokenTests.cs" />
|
||||
<Compile Include="Linq\JValueTests.cs" />
|
||||
<Compile Include="Linq\LinqToJsonTest.cs" />
|
||||
<Compile Include="PerformanceTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SilverlightTests.cs" />
|
||||
<Compile Include="TestFixtureBase.cs" />
|
||||
<Compile Include="Converters\XmlNodeConverterTest.cs" />
|
||||
<Compile Include="TestObjects\TypeClass.cs" />
|
||||
<Compile Include="TestObjects\TypedSubHashtable.cs" />
|
||||
<Compile Include="TestObjects\UserNullable.cs" />
|
||||
<Compile Include="Utilities\DynamicReflectionDelegateFactoryTests.cs" />
|
||||
<Compile Include="Utilities\ReflectionUtilsTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.Config" />
|
||||
<None Include="LinqToSql\LinqToSqlClasses.dbml">
|
||||
<Generator>MSLinqToSQLGenerator</Generator>
|
||||
<LastGenOutput>LinqToSqlClasses.designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="LinqToSql\LinqToSqlClasses.dbml.layout">
|
||||
<DependentUpon>LinqToSqlClasses.dbml</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="bunny_pancake.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Net35.csproj">
|
||||
<Project>{A9AE40FF-1A21-414A-9FE7-3BE13644CC6D}</Project>
|
||||
<Name>Newtonsoft.Json.Net35</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -65,6 +65,7 @@
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\NUnit\DotNet\nunit.framework.dll</HintPath>
|
||||
@@ -134,11 +135,13 @@
|
||||
<Compile Include="LinqToSql\Person.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="Serialization\ConstructorHandlingTests.cs" />
|
||||
<Compile Include="Serialization\ContractResolverTests.cs" />
|
||||
<Compile Include="Serialization\DefaultValueHandlingTests.cs" />
|
||||
<Compile Include="Serialization\DynamicTests.cs" />
|
||||
<Compile Include="Serialization\NullValueHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\Bar.cs" />
|
||||
<Compile Include="TestObjects\Car.cs" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !SILVERLIGHT && !PocketPC && !NET20
|
||||
#if !SILVERLIGHT && !PocketPC && !NET20 && !NET35
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -346,11 +346,11 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
return base.CreateContract(objectType);
|
||||
}
|
||||
|
||||
protected override IList<JsonProperty> CreateProperties(JsonObjectContract contract)
|
||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||
{
|
||||
IList<JsonProperty> properties = base.CreateProperties(contract);
|
||||
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
|
||||
|
||||
JsonPropertyCollection c = new JsonPropertyCollection(contract);
|
||||
JsonPropertyCollection c = new JsonPropertyCollection(type);
|
||||
CollectionUtils.AddRange(c, (IEnumerable)properties.Where(m => m.PropertyName != "Root"));
|
||||
|
||||
return c;
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
_startingWithChar = startingWithChar;
|
||||
}
|
||||
|
||||
protected override IList<JsonProperty> CreateProperties(JsonObjectContract contract)
|
||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||
{
|
||||
IList<JsonProperty> properties = base.CreateProperties(contract);
|
||||
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
|
||||
|
||||
// only serializer properties that start with the specified character
|
||||
properties =
|
||||
properties =
|
||||
properties.Where(p => p.PropertyName.StartsWith(_startingWithChar.ToString())).ToList();
|
||||
|
||||
return properties;
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
#if !(NET35 || NET20 || SILVERLIGHT)
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
public class DynamicTests : TestFixtureBase
|
||||
{
|
||||
public class DynamicChildObject
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public int Integer { get; set; }
|
||||
}
|
||||
|
||||
public class TestDynamicObject : DynamicObject
|
||||
{
|
||||
private readonly Dictionary<string, object> _members;
|
||||
|
||||
public int Int;
|
||||
public DynamicChildObject ChildObject { get; set; }
|
||||
|
||||
internal Dictionary<string, object> Members
|
||||
{
|
||||
get { return _members; }
|
||||
}
|
||||
|
||||
public TestDynamicObject()
|
||||
{
|
||||
_members = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
public override IEnumerable<string> GetDynamicMemberNames()
|
||||
{
|
||||
return _members.Keys.Union(new[] { "Int", "ChildObject" });
|
||||
}
|
||||
|
||||
public override bool TryConvert(ConvertBinder binder, out object result)
|
||||
{
|
||||
Type targetType = binder.Type;
|
||||
|
||||
if (targetType == typeof(IDictionary<string, object>) ||
|
||||
targetType == typeof(IDictionary))
|
||||
{
|
||||
result = new Dictionary<string, object>(_members);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.TryConvert(binder, out result);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryDeleteMember(DeleteMemberBinder binder)
|
||||
{
|
||||
return _members.Remove(binder.Name);
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
return _members.TryGetValue(binder.Name, out result);
|
||||
}
|
||||
|
||||
public override bool TrySetMember(SetMemberBinder binder, object value)
|
||||
{
|
||||
_members[binder.Name] = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class ErrorSettingDynamicObject : DynamicObject
|
||||
{
|
||||
public override bool TrySetMember(SetMemberBinder binder, object value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeDynamicObject()
|
||||
{
|
||||
TestDynamicObject dynamicObject = new TestDynamicObject();
|
||||
|
||||
dynamic d = dynamicObject;
|
||||
d.Int = 1;
|
||||
d.Decimal = 99.9d;
|
||||
d.ChildObject = new DynamicChildObject();
|
||||
|
||||
Dictionary<string, object> values = new Dictionary<string, object>();
|
||||
|
||||
foreach (string memberName in dynamicObject.GetDynamicMemberNames())
|
||||
{
|
||||
object value;
|
||||
dynamicObject.TryGetMember(memberName, out value);
|
||||
|
||||
values.Add(memberName, value);
|
||||
}
|
||||
|
||||
Assert.AreEqual(d.Int, values["Int"]);
|
||||
Assert.AreEqual(d.Decimal, values["Decimal"]);
|
||||
Assert.AreEqual(d.ChildObject, values["ChildObject"]);
|
||||
|
||||
string json = JsonConvert.SerializeObject(dynamicObject, Formatting.Indented);
|
||||
Assert.AreEqual(@"{
|
||||
""Decimal"": 99.9,
|
||||
""Int"": 1,
|
||||
""ChildObject"": {
|
||||
""Text"": null,
|
||||
""Integer"": 0
|
||||
}
|
||||
}", json);
|
||||
|
||||
TestDynamicObject newDynamicObject = JsonConvert.DeserializeObject<TestDynamicObject>(json);
|
||||
d = newDynamicObject;
|
||||
|
||||
Assert.AreEqual(99.9, d.Decimal);
|
||||
Assert.AreEqual(1, d.Int);
|
||||
Assert.AreEqual(dynamicObject.ChildObject.Integer, d.ChildObject.Integer);
|
||||
Assert.AreEqual(dynamicObject.ChildObject.Text, d.ChildObject.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void sdfsdf()
|
||||
{
|
||||
ErrorSettingDynamicObject d = JsonConvert.DeserializeObject<ErrorSettingDynamicObject>("{'hi':5}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeDynamicObjectWithObjectTracking()
|
||||
{
|
||||
dynamic o = new ExpandoObject();
|
||||
o.Text = "Text!";
|
||||
o.Integer = int.MaxValue;
|
||||
o.DynamicChildObject = new DynamicChildObject
|
||||
{
|
||||
Integer = int.MinValue,
|
||||
Text = "Child text!"
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(o, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Simple);
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""$type"": ""System.Dynamic.ExpandoObject, System.Core"",
|
||||
""Text"": ""Text!"",
|
||||
""Integer"": 2147483647,
|
||||
""DynamicChildObject"": {
|
||||
""$type"": """ + dynamicChildObjectTypeName + @""",
|
||||
""Text"": ""Child text!"",
|
||||
""Integer"": -2147483648
|
||||
}
|
||||
}", json);
|
||||
|
||||
dynamic n = JsonConvert.DeserializeObject(json, null, new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All
|
||||
});
|
||||
|
||||
Assert.IsInstanceOfType(typeof(ExpandoObject), n);
|
||||
Assert.AreEqual("Text!", n.Text);
|
||||
Assert.AreEqual(int.MaxValue, n.Integer);
|
||||
|
||||
Assert.IsInstanceOfType(typeof(DynamicChildObject), n.DynamicChildObject);
|
||||
Assert.AreEqual("Child text!", n.DynamicChildObject.Text);
|
||||
Assert.AreEqual(int.MinValue, n.DynamicChildObject.Integer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -23,7 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
#if !(NET35 || NET20 || SILVERLIGHT)
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
@@ -27,6 +27,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
#if !SILVERLIGHT && !PocketPC && !NET20
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Web.Script.Serialization;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -52,6 +53,10 @@ using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq.Expressions;
|
||||
#endif
|
||||
#if !(NET35 || NET20 || SILVERLIGHT)
|
||||
using System.Dynamic;
|
||||
#endif
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
@@ -3019,7 +3024,7 @@ keyword such as type of business.""
|
||||
PosDouble p = (PosDouble)value;
|
||||
|
||||
if (p != null)
|
||||
writer.WriteRawValue(String.Format("new PosD({0},{1})", p.X, p.Y));
|
||||
writer.WriteRawValue(String.Format(CultureInfo.InvariantCulture, "new PosD({0},{1})", p.X, p.Y));
|
||||
else
|
||||
writer.WriteNull();
|
||||
}
|
||||
@@ -3573,5 +3578,45 @@ keyword such as type of business.""
|
||||
""event"": ""derived""
|
||||
}", json);
|
||||
}
|
||||
|
||||
#if !(NET35 || NET20 || SILVERLIGHT)
|
||||
[Test]
|
||||
public void SerializeExpandoObject()
|
||||
{
|
||||
dynamic expando = new ExpandoObject();
|
||||
expando.Int = 1;
|
||||
expando.Decimal = 99.9d;
|
||||
expando.Complex = new ExpandoObject();
|
||||
expando.Complex.String = "I am a string";
|
||||
expando.Complex.DateTime = new DateTime(2000, 12, 20, 18, 55, 0, DateTimeKind.Utc);
|
||||
|
||||
string json = JsonConvert.SerializeObject(expando, Formatting.Indented);
|
||||
Assert.AreEqual(@"{
|
||||
""Int"": 1,
|
||||
""Decimal"": 99.9,
|
||||
""Complex"": {
|
||||
""String"": ""I am a string"",
|
||||
""DateTime"": ""\/Date(977338500000)\/""
|
||||
}
|
||||
}", json);
|
||||
|
||||
IDictionary<string, object> newExpando = JsonConvert.DeserializeObject<ExpandoObject>(json);
|
||||
|
||||
Assert.IsInstanceOfType(typeof(long), newExpando["Int"]);
|
||||
Assert.AreEqual(expando.Int, newExpando["Int"]);
|
||||
|
||||
Assert.IsInstanceOfType(typeof(double), newExpando["Decimal"]);
|
||||
Assert.AreEqual(expando.Decimal, newExpando["Decimal"]);
|
||||
|
||||
Assert.IsInstanceOfType(typeof(JObject), newExpando["Complex"]);
|
||||
JObject o = (JObject)newExpando["Complex"];
|
||||
|
||||
Assert.IsInstanceOfType(typeof(string), ((JValue)o["String"]).Value);
|
||||
Assert.AreEqual(expando.Complex.String, (string)o["String"]);
|
||||
|
||||
Assert.IsInstanceOfType(typeof(DateTime), ((JValue)o["DateTime"]).Value);
|
||||
Assert.AreEqual(expando.Complex.DateTime, (DateTime)o["DateTime"]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -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 || SILVERLIGHT)
|
||||
#if !(NET20 || NET35 || SILVERLIGHT)
|
||||
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]);
|
||||
|
||||
@@ -4,6 +4,7 @@ using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests
|
||||
{
|
||||
// todo: need to fix this to get WP unit tests running off right dlls
|
||||
#if SILVERLIGHT
|
||||
[TestFixture]
|
||||
public class SilverlightTests
|
||||
|
||||
Reference in New Issue
Block a user