-XML documentation
-Changed OnError to be available in .NET 2.0, Silverlight and Compact Framework builds -Added StreamingContext stand-in for frameworks where it isn't available -Split test classes out of JsonSerializerTests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#region License
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
|
||||
<Compile Include="Serialization\PopulateTests.cs" />
|
||||
<Compile Include="Serialization\PreserveReferencesHandlingTests.cs" />
|
||||
<Compile Include="Serialization\SerializationErrorHandlingTests.cs" />
|
||||
<Compile Include="Serialization\SerializationEventAttributeTests.cs" />
|
||||
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\AbstractGenericBase.cs" />
|
||||
@@ -86,29 +87,45 @@
|
||||
<Compile Include="TestObjects\ClassAndMemberConverterClass.cs" />
|
||||
<Compile Include="TestObjects\ClassConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\ConstructorCaseSensitivityClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClass.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\CircularReferenceWithIdClass.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="TestObjects\DefaultValueAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\DictionaryInterfaceClass.cs" />
|
||||
<Compile Include="TestObjects\DoubleClass.cs" />
|
||||
<Compile Include="TestObjects\EmployeeReference.cs" />
|
||||
<Compile Include="TestObjects\Event.cs" />
|
||||
<Compile Include="TestObjects\GenericImpl.cs" />
|
||||
<Compile Include="TestObjects\GenericListAndDictionaryInterfaceProperties.cs" />
|
||||
<Compile Include="TestObjects\GetOnlyPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\GoogleMapGeocoderStructure.cs" />
|
||||
<Compile Include="TestObjects\IncompatibleJsonAttributeClass.cs" />
|
||||
<Compile Include="TestObjects\InterfacePropertyTestClass.cs" />
|
||||
<Compile Include="TestObjects\Invoice.cs" />
|
||||
<Compile Include="TestObjects\JaggedArray.cs" />
|
||||
<Compile Include="TestObjects\JsonIgnoreAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyWithHandlingValues.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObject.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObjectCollection.cs" />
|
||||
<Compile Include="TestObjects\ListTestClass.cs" />
|
||||
<Compile Include="TestObjects\LogEntry.cs" />
|
||||
<Compile Include="TestObjects\MemberConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\MethodExecutorObject.cs" />
|
||||
<Compile Include="TestObjects\MyClass.cs" />
|
||||
<Compile Include="TestObjects\Name.cs" />
|
||||
<Compile Include="TestObjects\NonRequest.cs" />
|
||||
<Compile Include="TestObjects\NullableDateTimeTestClass.cs" />
|
||||
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
|
||||
<Compile Include="TestObjects\PersonRaw.cs" />
|
||||
<Compile Include="TestObjects\PhoneNumber.cs" />
|
||||
<Compile Include="TestObjects\PrivateMembersClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyCase.cs" />
|
||||
<Compile Include="TestObjects\RequestOnly.cs" />
|
||||
<Compile Include="TestObjects\RequiredMembersClass.cs" />
|
||||
<Compile Include="TestObjects\RoleTransfer.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestDictionary.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestList.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestObject.cs" />
|
||||
@@ -126,6 +143,7 @@
|
||||
<Compile Include="TestObjects\Product.cs" />
|
||||
<Compile Include="TestObjects\ProductCollection.cs" />
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\SetOnlyPropertyClass2.cs" />
|
||||
<Compile Include="TestObjects\Shortie.cs" />
|
||||
<Compile Include="TestObjects\Store.cs" />
|
||||
<Compile Include="TestObjects\StoreColor.cs" />
|
||||
@@ -151,9 +169,12 @@
|
||||
<Compile Include="SilverlightTests.cs" />
|
||||
<Compile Include="TestFixtureBase.cs" />
|
||||
<Compile Include="Converters\XmlNodeConverterTest.cs" />
|
||||
<Compile Include="TestObjects\SubKlass.cs" />
|
||||
<Compile Include="TestObjects\SuperKlass.cs" />
|
||||
<Compile Include="TestObjects\TypeClass.cs" />
|
||||
<Compile Include="TestObjects\TypedSubHashtable.cs" />
|
||||
<Compile Include="TestObjects\UserNullable.cs" />
|
||||
<Compile Include="TestObjects\VersionKeyedCollection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Compact.csproj">
|
||||
|
||||
@@ -72,16 +72,33 @@
|
||||
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JTypeDescriptionProviderTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JTypeDescriptorTests.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\DictionaryInterfaceClass.cs" />
|
||||
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
|
||||
<Compile Include="TestObjects\Event.cs" />
|
||||
<Compile Include="TestObjects\GoogleMapGeocoderStructure.cs" />
|
||||
<Compile Include="TestObjects\InterfacePropertyTestClass.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyClass.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="TestObjects\ListTestClass.cs" />
|
||||
<Compile Include="TestObjects\LogEntry.cs" />
|
||||
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\NonRequest.cs" />
|
||||
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
|
||||
<Compile Include="Serialization\PopulateTests.cs" />
|
||||
<Compile Include="TestObjects\PropertyCase.cs" />
|
||||
<Compile Include="TestObjects\RequestOnly.cs" />
|
||||
<Compile Include="TestObjects\RoleTransfer.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="TestObjects\SetOnlyPropertyClass2.cs" />
|
||||
<Compile Include="TestObjects\SubKlass.cs" />
|
||||
<Compile Include="TestObjects\SuperKlass.cs" />
|
||||
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\AbstractGenericBase.cs" />
|
||||
<Compile Include="TestObjects\ArgumentConverterPrecedenceClassConverter.cs" />
|
||||
@@ -93,6 +110,7 @@
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClass.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\CircularReferenceWithIdClass.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="TestObjects\EmployeeReference.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyWithHandlingValues.cs" />
|
||||
<Compile Include="TestObjects\DefaultValueAttributeTestClass.cs" />
|
||||
@@ -103,6 +121,8 @@
|
||||
<Compile Include="TestObjects\IncompatibleJsonAttributeClass.cs" />
|
||||
<Compile Include="TestObjects\Invoice.cs" />
|
||||
<Compile Include="TestObjects\JsonIgnoreAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObject.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObjectCollection.cs" />
|
||||
<Compile Include="TestObjects\MemberConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\MethodExecutorObject.cs" />
|
||||
<Compile Include="TestObjects\JaggedArray.cs" />
|
||||
@@ -160,6 +180,7 @@
|
||||
<Compile Include="TestObjects\TypeClass.cs" />
|
||||
<Compile Include="TestObjects\TypedSubHashtable.cs" />
|
||||
<Compile Include="TestObjects\UserNullable.cs" />
|
||||
<Compile Include="TestObjects\VersionKeyedCollection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
|
||||
<Compile Include="Serialization\PopulateTests.cs" />
|
||||
<Compile Include="Serialization\PreserveReferencesHandlingTests.cs" />
|
||||
<Compile Include="Serialization\SerializationErrorHandlingTests.cs" />
|
||||
<Compile Include="Serialization\SerializationEventAttributeTests.cs" />
|
||||
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\AbstractGenericBase.cs" />
|
||||
@@ -92,29 +93,45 @@
|
||||
<Compile Include="TestObjects\ClassAndMemberConverterClass.cs" />
|
||||
<Compile Include="TestObjects\ClassConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\ConstructorCaseSensitivityClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClass.cs" />
|
||||
<Compile Include="TestObjects\ConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\CircularReferenceWithIdClass.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="TestObjects\DefaultValueAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\DictionaryInterfaceClass.cs" />
|
||||
<Compile Include="TestObjects\DoubleClass.cs" />
|
||||
<Compile Include="TestObjects\EmployeeReference.cs" />
|
||||
<Compile Include="TestObjects\Event.cs" />
|
||||
<Compile Include="TestObjects\GenericImpl.cs" />
|
||||
<Compile Include="TestObjects\GenericListAndDictionaryInterfaceProperties.cs" />
|
||||
<Compile Include="TestObjects\GetOnlyPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\GoogleMapGeocoderStructure.cs" />
|
||||
<Compile Include="TestObjects\IncompatibleJsonAttributeClass.cs" />
|
||||
<Compile Include="TestObjects\InterfacePropertyTestClass.cs" />
|
||||
<Compile Include="TestObjects\Invoice.cs" />
|
||||
<Compile Include="TestObjects\JaggedArray.cs" />
|
||||
<Compile Include="TestObjects\JsonIgnoreAttributeTestClass.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyWithHandlingValues.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObject.cs" />
|
||||
<Compile Include="TestObjects\ListErrorObjectCollection.cs" />
|
||||
<Compile Include="TestObjects\ListTestClass.cs" />
|
||||
<Compile Include="TestObjects\LogEntry.cs" />
|
||||
<Compile Include="TestObjects\MemberConverterPrecedenceClassConverter.cs" />
|
||||
<Compile Include="TestObjects\MethodExecutorObject.cs" />
|
||||
<Compile Include="TestObjects\MyClass.cs" />
|
||||
<Compile Include="TestObjects\Name.cs" />
|
||||
<Compile Include="TestObjects\NonRequest.cs" />
|
||||
<Compile Include="TestObjects\NullableDateTimeTestClass.cs" />
|
||||
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
|
||||
<Compile Include="TestObjects\PersonRaw.cs" />
|
||||
<Compile Include="TestObjects\PhoneNumber.cs" />
|
||||
<Compile Include="TestObjects\PrivateMembersClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyCase.cs" />
|
||||
<Compile Include="TestObjects\RequestOnly.cs" />
|
||||
<Compile Include="TestObjects\RequiredMembersClass.cs" />
|
||||
<Compile Include="TestObjects\RoleTransfer.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestDictionary.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestList.cs" />
|
||||
<Compile Include="TestObjects\SerializationEventTestObject.cs" />
|
||||
@@ -132,6 +149,7 @@
|
||||
<Compile Include="TestObjects\Product.cs" />
|
||||
<Compile Include="TestObjects\ProductCollection.cs" />
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\SetOnlyPropertyClass2.cs" />
|
||||
<Compile Include="TestObjects\Shortie.cs" />
|
||||
<Compile Include="TestObjects\Store.cs" />
|
||||
<Compile Include="TestObjects\StoreColor.cs" />
|
||||
@@ -157,9 +175,12 @@
|
||||
<Compile Include="SilverlightTests.cs" />
|
||||
<Compile Include="TestFixtureBase.cs" />
|
||||
<Compile Include="Converters\XmlNodeConverterTest.cs" />
|
||||
<Compile Include="TestObjects\SubKlass.cs" />
|
||||
<Compile Include="TestObjects\SuperKlass.cs" />
|
||||
<Compile Include="TestObjects\TypeClass.cs" />
|
||||
<Compile Include="TestObjects\TypedSubHashtable.cs" />
|
||||
<Compile Include="TestObjects\UserNullable.cs" />
|
||||
<Compile Include="TestObjects\VersionKeyedCollection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Silverlight.csproj">
|
||||
|
||||
@@ -109,9 +109,19 @@
|
||||
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JTypeDescriptionProviderTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JTypeDescriptorTests.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" />
|
||||
@@ -119,6 +129,17 @@
|
||||
<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\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" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -17,8 +17,8 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Newtonsoft")]
|
||||
[assembly: AssemblyProduct("Newtonsoft Json.NET Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © Newtonsoft 2008")]
|
||||
[assembly: AssemblyProduct("Newtonsoft Json.NET Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Newtonsoft 2008")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
||||
@@ -332,26 +332,6 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(nestedTorrentsArray.Children().Count(), 19);
|
||||
}
|
||||
|
||||
public class JsonPropertyClass
|
||||
{
|
||||
[JsonProperty("pie")]
|
||||
public string Pie = "Yum";
|
||||
|
||||
[JsonIgnore]
|
||||
public string pie = "No pie for you!";
|
||||
|
||||
public string pie1 = "PieChart!";
|
||||
|
||||
private int _sweetCakesCount;
|
||||
|
||||
[JsonProperty("sweet_cakes_count")]
|
||||
public int SweetCakesCount
|
||||
{
|
||||
get { return _sweetCakesCount; }
|
||||
set { _sweetCakesCount = value; }
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JsonPropertyClassSerialize()
|
||||
{
|
||||
@@ -1079,72 +1059,6 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(json, after);
|
||||
}
|
||||
|
||||
public class GoogleMapGeocoderStructure
|
||||
{
|
||||
public string Name;
|
||||
public Status Status;
|
||||
public List<Placemark> Placemark;
|
||||
}
|
||||
|
||||
public class Status
|
||||
{
|
||||
public string Request;
|
||||
public string Code;
|
||||
}
|
||||
|
||||
public class Placemark
|
||||
{
|
||||
public string Address;
|
||||
public AddressDetails AddressDetails;
|
||||
public Point Point;
|
||||
}
|
||||
|
||||
public class AddressDetails
|
||||
{
|
||||
public int Accuracy;
|
||||
public Country Country;
|
||||
}
|
||||
|
||||
public class Country
|
||||
{
|
||||
public string CountryNameCode;
|
||||
public AdministrativeArea AdministrativeArea;
|
||||
}
|
||||
|
||||
public class AdministrativeArea
|
||||
{
|
||||
public string AdministrativeAreaName;
|
||||
public SubAdministrativeArea SubAdministrativeArea;
|
||||
}
|
||||
|
||||
public class SubAdministrativeArea
|
||||
{
|
||||
public string SubAdministrativeAreaName;
|
||||
public Locality Locality;
|
||||
}
|
||||
|
||||
public class Locality
|
||||
{
|
||||
public string LocalityName;
|
||||
public Thoroughfare Thoroughfare;
|
||||
public PostalCode PostalCode;
|
||||
}
|
||||
|
||||
public class Thoroughfare
|
||||
{
|
||||
public string ThoroughfareName;
|
||||
}
|
||||
|
||||
public class PostalCode
|
||||
{
|
||||
public string PostalCodeNumber;
|
||||
}
|
||||
|
||||
public class Point
|
||||
{
|
||||
public List<decimal> Coordinates;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeGoogleGeoCode()
|
||||
{
|
||||
@@ -1191,38 +1105,14 @@ keyword such as type of business.""
|
||||
GoogleMapGeocoderStructure jsonGoogleMapGeocoder = JsonConvert.DeserializeObject<GoogleMapGeocoderStructure>(json);
|
||||
}
|
||||
|
||||
public class Co : ICo
|
||||
{
|
||||
public String Name { get; set; }
|
||||
}
|
||||
|
||||
public interface ICo
|
||||
{
|
||||
String Name { get; set; }
|
||||
}
|
||||
|
||||
public interface ITest
|
||||
{
|
||||
ICo co { get; set; }
|
||||
}
|
||||
|
||||
public class Test : ITest
|
||||
{
|
||||
public ICo co { get; set; }
|
||||
|
||||
public Test()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Could not create an instance of type Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+ICo. Type is an interface or abstract class and cannot be instantated.")]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.ICo. Type is an interface or abstract class and cannot be instantated.")]
|
||||
public void DeserializeInterfaceProperty()
|
||||
{
|
||||
Test testClass = new Test();
|
||||
InterfacePropertyTestClass testClass = new InterfacePropertyTestClass();
|
||||
testClass.co = new Co();
|
||||
String strFromTest = JsonConvert.SerializeObject(testClass);
|
||||
Test testFromDe = (Test)JsonConvert.DeserializeObject(strFromTest, typeof(Test));
|
||||
InterfacePropertyTestClass testFromDe = (InterfacePropertyTestClass)JsonConvert.DeserializeObject(strFromTest, typeof(InterfacePropertyTestClass));
|
||||
}
|
||||
|
||||
private Person GetPerson()
|
||||
@@ -1259,12 +1149,6 @@ keyword such as type of business.""
|
||||
}
|
||||
}
|
||||
|
||||
public class LogEntry
|
||||
{
|
||||
public string Details { get; set; }
|
||||
public DateTime LogDate { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteJsonDates()
|
||||
{
|
||||
@@ -1334,14 +1218,6 @@ keyword such as type of business.""
|
||||
CollectionAssert.AreEqual(o.IDictionaryProperty.ToArray(), deserializedObject.IDictionaryProperty.ToArray());
|
||||
}
|
||||
|
||||
public class PropertyCase
|
||||
{
|
||||
public string firstName { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string lastName { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeBestMatchPropertyCase()
|
||||
{
|
||||
@@ -1361,18 +1237,6 @@ keyword such as type of business.""
|
||||
Assert.AreEqual("lastName", o.lastName);
|
||||
}
|
||||
|
||||
public class SuperKlass
|
||||
{
|
||||
public string SuperProp { get; set; }
|
||||
public SuperKlass() { SuperProp = "default superprop"; }
|
||||
}
|
||||
|
||||
public class SubKlass : SuperKlass
|
||||
{
|
||||
public string SubProp { get; set; }
|
||||
public SubKlass(string subprop) { SubProp = subprop; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializePropertiesOnToNonDefaultConstructor()
|
||||
{
|
||||
@@ -1423,18 +1287,6 @@ keyword such as type of business.""
|
||||
JsonConvert.SerializeObject(o, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
}
|
||||
|
||||
public class RequestOnly
|
||||
{
|
||||
public string Request { get; set; }
|
||||
}
|
||||
|
||||
public class NonRequest
|
||||
{
|
||||
public Guid Sid { get; set; }
|
||||
public Guid Uid { get; set; }
|
||||
public IList<string> FidOrder { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PartialClassDeserialize()
|
||||
{
|
||||
@@ -1565,33 +1417,6 @@ keyword such as type of business.""
|
||||
}
|
||||
#endif
|
||||
|
||||
public class DictionaryInterfaceClass
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public IDictionary<string, int> Dictionary { get; set; }
|
||||
public ICollection<int> Collection { get; set; }
|
||||
public EmployeeReference Employee { get; set; }
|
||||
public object Random { get; set; }
|
||||
|
||||
public DictionaryInterfaceClass()
|
||||
{
|
||||
Dictionary = new Dictionary<string, int>
|
||||
{
|
||||
{ "existing", 1 }
|
||||
};
|
||||
Collection = new List<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
Employee = new EmployeeReference
|
||||
{
|
||||
Name = "EmployeeName!"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeDictionaryInterface()
|
||||
{
|
||||
@@ -1720,25 +1545,6 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(@"{""bar"":{""baz"":13}}", json);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
public class Content : IEnumerable<Content>
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<Content> Children;
|
||||
[JsonProperty]
|
||||
public string Text;
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return Children.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator<Content> IEnumerable<Content>.GetEnumerator()
|
||||
{
|
||||
return Children.GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeEnumerableAsObject()
|
||||
{
|
||||
@@ -1794,25 +1600,6 @@ keyword such as type of business.""
|
||||
Assert.AreEqual("Second", content.Children[1].Text);
|
||||
}
|
||||
|
||||
public enum RoleTransferOperation
|
||||
{
|
||||
First,
|
||||
Second
|
||||
}
|
||||
|
||||
public enum RoleTransferDirection
|
||||
{
|
||||
First,
|
||||
Second
|
||||
}
|
||||
|
||||
public class RoleTransfer
|
||||
{
|
||||
public RoleTransferOperation Operation { get; set; } //This is enum type
|
||||
public string RoleName { get; set; }
|
||||
public RoleTransferDirection Direction { get; set; } //This is enum type
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RoleTransferTest()
|
||||
{
|
||||
@@ -1825,13 +1612,6 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(RoleTransferDirection.First, r.Direction);
|
||||
}
|
||||
|
||||
public class ObjectArrayPropertyTest
|
||||
{
|
||||
public string Action { get; set; }
|
||||
public string Method { get; set; }
|
||||
public object[] Data { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PrimitiveValuesInObjectArray()
|
||||
{
|
||||
@@ -1975,127 +1755,8 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(null, c.DateTimeField);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What types of events are there? Just sticking to a basic set of four for now.
|
||||
/// </summary>
|
||||
/// <remarks></remarks>
|
||||
public enum EventType
|
||||
{
|
||||
Debug = 0,
|
||||
Info = 1,
|
||||
Warning = 2,
|
||||
Error = 3
|
||||
}
|
||||
|
||||
public sealed class Event
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// If no current user is specified, returns Nothing (0 from VB)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks></remarks>
|
||||
private static int GetCurrentUserId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets either the application path or the current stack trace.
|
||||
/// NOTE: You MUST call this from the top level entry point. Otherwise,
|
||||
/// the stack trace will be buried in Logger itself.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks></remarks>
|
||||
private static string GetCurrentSubLocation()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
private string _sublocation;
|
||||
private int _userId;
|
||||
private EventType _type;
|
||||
private string _summary;
|
||||
private string _details;
|
||||
private string _stackTrace;
|
||||
private string _tag;
|
||||
private DateTime _time;
|
||||
|
||||
public Event(string summary)
|
||||
{
|
||||
_summary = summary;
|
||||
_time = DateTime.Now;
|
||||
|
||||
if (_userId == 0) _userId = GetCurrentUserId();
|
||||
//This call only works at top level for now.
|
||||
//If _stackTrace = Nothing Then _stackTrace = Environment.StackTrace
|
||||
if (_sublocation == null) _sublocation = GetCurrentSubLocation();
|
||||
}
|
||||
|
||||
public Event(string sublocation, int userId, EventType type, string summary, string details, string stackTrace, string tag)
|
||||
{
|
||||
_sublocation = sublocation;
|
||||
_userId = userId;
|
||||
_type = type;
|
||||
_summary = summary;
|
||||
_details = details;
|
||||
_stackTrace = stackTrace;
|
||||
_tag = tag;
|
||||
_time = DateTime.Now;
|
||||
|
||||
if (_userId == 0) _userId = GetCurrentUserId();
|
||||
//If _stackTrace = Nothing Then _stackTrace = Environment.StackTrace
|
||||
if (_sublocation == null) _sublocation = GetCurrentSubLocation();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{{ sublocation = {0}, userId = {1}, type = {2}, summary = {3}, details = {4}, stackTrace = {5}, tag = {6} }}", _sublocation, _userId, _type, _summary, _details, _stackTrace, _tag);
|
||||
}
|
||||
|
||||
public string sublocation
|
||||
{
|
||||
get { return _sublocation; }
|
||||
set { _sublocation = value; }
|
||||
}
|
||||
public int userId
|
||||
{
|
||||
get { return _userId; }
|
||||
set { _userId = value; }
|
||||
}
|
||||
public EventType type
|
||||
{
|
||||
get { return _type; }
|
||||
set { _type = value; }
|
||||
}
|
||||
public string summary
|
||||
{
|
||||
get { return _summary; }
|
||||
set { _summary = value; }
|
||||
}
|
||||
public string details
|
||||
{
|
||||
get { return _details; }
|
||||
set { _details = value; }
|
||||
}
|
||||
public string stackTrace
|
||||
{
|
||||
get { return _stackTrace; }
|
||||
set { _stackTrace = value; }
|
||||
}
|
||||
public string tag
|
||||
{
|
||||
get { return _tag; }
|
||||
set { _tag = value; }
|
||||
}
|
||||
public DateTime time
|
||||
{
|
||||
get { return _time; }
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Unable to determine which constructor to use for type Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+Event. A class with no default constructor should have only one constructor with arguments.")]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Unable to determine which constructor to use for type Newtonsoft.Json.Tests.TestObjects.Event. A class with no default constructor should have only one constructor with arguments.")]
|
||||
public void FailWhenClassWithNoDefaultConstructorHasMultipleConstructorsWithArguments()
|
||||
{
|
||||
string json = @"{""sublocation"":""AlertEmailSender.Program.Main"",""userId"":0,""type"":0,""summary"":""Loading settings variables"",""details"":null,""stackTrace"":"" at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)\r\n at System.Environment.get_StackTrace()\r\n at mr.Logging.Event..ctor(String summary) in C:\\Projects\\MRUtils\\Logging\\Event.vb:line 71\r\n at AlertEmailSender.Program.Main(String[] args) in C:\\Projects\\AlertEmailSender\\AlertEmailSender\\Program.cs:line 25"",""tag"":null,""time"":""\/Date(1249591032026-0400)\/""}";
|
||||
@@ -2103,19 +1764,6 @@ keyword such as type of business.""
|
||||
Event e = JsonConvert.DeserializeObject<Event>(json);
|
||||
}
|
||||
|
||||
public class SetOnlyPropertyClass2
|
||||
{
|
||||
private object _value;
|
||||
public object SetOnlyProperty
|
||||
{
|
||||
set { _value = value; }
|
||||
}
|
||||
public object GetValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeObjectSetOnlyProperty()
|
||||
{
|
||||
@@ -2128,29 +1776,12 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(5, (int)a[a.Count - 1]);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class list
|
||||
{
|
||||
[JsonProperty]
|
||||
public string id { get; set; }
|
||||
[JsonProperty]
|
||||
public List<ListItem> items { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class ListItem
|
||||
{
|
||||
[JsonProperty]
|
||||
public string id { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeOptInClasses()
|
||||
{
|
||||
string json = @"{id: ""12"", name: ""test"", items: [{id: ""112"", name: ""testing""}]}";
|
||||
|
||||
list l = JsonConvert.DeserializeObject<list>(json);
|
||||
ListTestClass l = JsonConvert.DeserializeObject<ListTestClass>(json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -2163,5 +1794,22 @@ keyword such as type of business.""
|
||||
Assert.AreEqual(null, l[1]);
|
||||
Assert.AreEqual(1.1m, l[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeNullableListWithNullss()
|
||||
{
|
||||
//JavaScriptSerializer s = new JavaScriptSerializer();
|
||||
//s.Deserialize<List<decimal?>>("[ 3.3, null, 1.1 ] ");
|
||||
|
||||
//DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(List<decimal?>));
|
||||
//s.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes("[ 3.3, null, 1.1 ] ")));
|
||||
|
||||
List<decimal?> l = JsonConvert.DeserializeObject<List<decimal?>>("[ 3.3, null, 1.1 ] ");
|
||||
Assert.AreEqual(3, l.Count);
|
||||
|
||||
Assert.AreEqual(3.3m, l[0]);
|
||||
Assert.AreEqual(null, l[1]);
|
||||
Assert.AreEqual(1.1m, l[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
public class SerializationErrorHandlingTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void ErrorDeserializingListHandled()
|
||||
{
|
||||
string json = @"[
|
||||
{
|
||||
""Name"": ""Jim"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
},
|
||||
{
|
||||
""Name"": ""Jim"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
}
|
||||
]";
|
||||
|
||||
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
|
||||
Assert.AreEqual(1, c.Count);
|
||||
Assert.AreEqual(1, c.Messages.Count);
|
||||
Assert.AreEqual("Error message for member 1 = An item with the same key has already been added.", c.Messages[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorSerializingListHandled()
|
||||
{
|
||||
VersionKeyedCollection c = new VersionKeyedCollection();
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jim",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jimbo",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jimmy",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jim Bean",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""Jimbo"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
},
|
||||
{
|
||||
""Name"": ""Jim Bean"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
}
|
||||
]", json);
|
||||
|
||||
Assert.AreEqual(2, c.Messages.Count);
|
||||
Assert.AreEqual("Error message for member 0 = Index even: 0", c.Messages[0]);
|
||||
Assert.AreEqual("Error message for member 2 = Index even: 2", c.Messages[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializingErrorInChildObject()
|
||||
{
|
||||
ListErrorObjectCollection c = JsonConvert.DeserializeObject<ListErrorObjectCollection>(@"[
|
||||
{
|
||||
""Member"": ""Value1"",
|
||||
""Member2"": null
|
||||
},
|
||||
{
|
||||
""Member"": ""Value2""
|
||||
},
|
||||
{
|
||||
""ThrowError"": ""Value"",
|
||||
""Object"": {
|
||||
""Array"": [
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""ThrowError"": ""Handle this!"",
|
||||
""Member"": ""Value3""
|
||||
}
|
||||
]");
|
||||
|
||||
Assert.AreEqual(3, c.Count);
|
||||
Assert.AreEqual("Value1", c[0].Member);
|
||||
Assert.AreEqual("Value2", c[1].Member);
|
||||
Assert.AreEqual("Value3", c[2].Member);
|
||||
Assert.AreEqual("Handle this!", c[2].ThrowError);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializingErrorInChildObject()
|
||||
{
|
||||
ListErrorObjectCollection c = new ListErrorObjectCollection
|
||||
{
|
||||
new ListErrorObject
|
||||
{
|
||||
Member = "Value1",
|
||||
ThrowError = "Handle this!",
|
||||
Member2 = "Member1"
|
||||
},
|
||||
new ListErrorObject
|
||||
{
|
||||
Member = "Value2",
|
||||
Member2 = "Member2"
|
||||
},
|
||||
new ListErrorObject
|
||||
{
|
||||
Member = "Value3",
|
||||
ThrowError = "Handle that!",
|
||||
Member2 = "Member3"
|
||||
}
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Member"": ""Value1"",
|
||||
""ThrowError"": ""Handle this!"",
|
||||
""Member2"": ""Member1""
|
||||
},
|
||||
{
|
||||
""Member"": ""Value2""
|
||||
},
|
||||
{
|
||||
""Member"": ""Value3"",
|
||||
""ThrowError"": ""Handle that!"",
|
||||
""Member2"": ""Member3""
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializingErrorInDateTimeCollection()
|
||||
{
|
||||
DateTimeErrorObjectCollection c = JsonConvert.DeserializeObject<DateTimeErrorObjectCollection>(@"[
|
||||
""2009-09-09T00:00:00Z"",
|
||||
""kjhkjhkjhkjh"",
|
||||
[
|
||||
1
|
||||
],
|
||||
""1977-02-20T00:00:00Z"",
|
||||
null,
|
||||
""2000-12-01T00:00:00Z""
|
||||
]", new IsoDateTimeConverter());
|
||||
|
||||
Assert.AreEqual(3, c.Count);
|
||||
Assert.AreEqual(new DateTime(2009, 9, 9, 0, 0, 0, DateTimeKind.Utc), c[0]);
|
||||
Assert.AreEqual(new DateTime(1977, 2, 20, 0, 0, 0, DateTimeKind.Utc), c[1]);
|
||||
Assert.AreEqual(new DateTime(2000, 12, 1, 0, 0, 0, DateTimeKind.Utc), c[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,19 +25,14 @@
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
using NUnit.Framework;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
@@ -114,254 +109,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual("This value was set after deserialization.", obj.Member4);
|
||||
}
|
||||
|
||||
public class ListErrorObject
|
||||
{
|
||||
public string Member { get; set; }
|
||||
|
||||
private string _throwError;
|
||||
public string ThrowError
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_throwError != null)
|
||||
return _throwError;
|
||||
|
||||
throw new Exception("ListErrorObject.ThrowError get error!");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.StartsWith("Handle"))
|
||||
{
|
||||
_throwError = value;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception("ListErrorObject.ThrowError set error!");
|
||||
}
|
||||
}
|
||||
|
||||
public string Member2 { get; set; }
|
||||
}
|
||||
|
||||
public class ListErrorObjectCollection : Collection<ListErrorObject>
|
||||
{
|
||||
[OnError]
|
||||
internal void OnErrorMethod(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DateTimeErrorObjectCollection : Collection<DateTime>
|
||||
{
|
||||
[OnError]
|
||||
internal void OnErrorMethod(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class VersionKeyedCollection : KeyedCollection<string, Person>, IList
|
||||
{
|
||||
public List<string> Messages { get; set; }
|
||||
|
||||
public VersionKeyedCollection()
|
||||
{
|
||||
Messages = new List<string>();
|
||||
}
|
||||
|
||||
protected override string GetKeyForItem(Person item)
|
||||
{
|
||||
return item.Name;
|
||||
}
|
||||
|
||||
[OnError]
|
||||
internal void OnErrorMethod(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
Messages.Add("Error message for member " + errorContext.Member + " = " + errorContext.Error.Message);
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
|
||||
object IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index % 2 == 0)
|
||||
throw new Exception("Index even: " + index);
|
||||
|
||||
return this[index];
|
||||
}
|
||||
set { this[index] = (Person)value; }
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorDeserializingListHandled()
|
||||
{
|
||||
string json = @"[
|
||||
{
|
||||
""Name"": ""Jim"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
},
|
||||
{
|
||||
""Name"": ""Jim"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
}
|
||||
]";
|
||||
|
||||
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
|
||||
Assert.AreEqual(1, c.Count);
|
||||
Assert.AreEqual(1, c.Messages.Count);
|
||||
Assert.AreEqual("Error message for member 1 = An item with the same key has already been added.", c.Messages[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorSerializingListHandled()
|
||||
{
|
||||
VersionKeyedCollection c = new VersionKeyedCollection();
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jim",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jimbo",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jimmy",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
c.Add(new Person
|
||||
{
|
||||
Name = "Jim Bean",
|
||||
BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
|
||||
LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
|
||||
});
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""Jimbo"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
},
|
||||
{
|
||||
""Name"": ""Jim Bean"",
|
||||
""BirthDate"": ""\/Date(978048000000)\/"",
|
||||
""LastModified"": ""\/Date(978048000000)\/""
|
||||
}
|
||||
]", json);
|
||||
|
||||
Assert.AreEqual(2, c.Messages.Count);
|
||||
Assert.AreEqual("Error message for member 0 = Index even: 0", c.Messages[0]);
|
||||
Assert.AreEqual("Error message for member 2 = Index even: 2", c.Messages[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializingErrorInChildObject()
|
||||
{
|
||||
ListErrorObjectCollection c = JsonConvert.DeserializeObject<ListErrorObjectCollection>(@"[
|
||||
{
|
||||
""Member"": ""Value1"",
|
||||
""Member2"": null
|
||||
},
|
||||
{
|
||||
""Member"": ""Value2""
|
||||
},
|
||||
{
|
||||
""ThrowError"": ""Value"",
|
||||
""Object"": {
|
||||
""Array"": [
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""ThrowError"": ""Handle this!"",
|
||||
""Member"": ""Value3""
|
||||
}
|
||||
]");
|
||||
|
||||
Assert.AreEqual(3, c.Count);
|
||||
Assert.AreEqual("Value1", c[0].Member);
|
||||
Assert.AreEqual("Value2", c[1].Member);
|
||||
Assert.AreEqual("Value3", c[2].Member);
|
||||
Assert.AreEqual("Handle this!", c[2].ThrowError);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializingErrorInChildObject()
|
||||
{
|
||||
ListErrorObjectCollection c = new ListErrorObjectCollection
|
||||
{
|
||||
new ListErrorObject
|
||||
{
|
||||
Member = "Value1",
|
||||
ThrowError = "Handle this!",
|
||||
Member2 = "Member1"
|
||||
},
|
||||
new ListErrorObject
|
||||
{
|
||||
Member = "Value2",
|
||||
Member2 = "Member2"
|
||||
},
|
||||
new ListErrorObject
|
||||
{
|
||||
Member = "Value3",
|
||||
ThrowError = "Handle that!",
|
||||
Member2 = "Member3"
|
||||
}
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(c, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Member"": ""Value1"",
|
||||
""ThrowError"": ""Handle this!"",
|
||||
""Member2"": ""Member1""
|
||||
},
|
||||
{
|
||||
""Member"": ""Value2""
|
||||
},
|
||||
{
|
||||
""Member"": ""Value3"",
|
||||
""ThrowError"": ""Handle that!"",
|
||||
""Member2"": ""Member3""
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializingErrorInDateTimeCollection()
|
||||
{
|
||||
DateTimeErrorObjectCollection c = JsonConvert.DeserializeObject<DateTimeErrorObjectCollection>(@"[
|
||||
""2009-09-09T00:00:00Z"",
|
||||
""kjhkjhkjhkjh"",
|
||||
[
|
||||
1
|
||||
],
|
||||
""1977-02-20T00:00:00Z"",
|
||||
null,
|
||||
""2000-12-01T00:00:00Z""
|
||||
]", new IsoDateTimeConverter());
|
||||
|
||||
Assert.AreEqual(3, c.Count);
|
||||
Assert.AreEqual(new DateTime(2009, 9, 9, 0, 0, 0, DateTimeKind.Utc), c[0]);
|
||||
Assert.AreEqual(new DateTime(1977, 2, 20, 0, 0, 0, DateTimeKind.Utc), c[1]);
|
||||
Assert.AreEqual(new DateTime(2000, 12, 1, 0, 0, 0, DateTimeKind.Utc), c[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ListEvents()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
public class Content : IEnumerable<Content>
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<Content> Children;
|
||||
[JsonProperty]
|
||||
public string Text;
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return Children.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator<Content> IEnumerable<Content>.GetEnumerator()
|
||||
{
|
||||
return Children.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class DateTimeErrorObjectCollection : Collection<DateTime>
|
||||
{
|
||||
[OnError]
|
||||
internal void OnErrorMethod(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class DictionaryInterfaceClass
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public IDictionary<string, int> Dictionary { get; set; }
|
||||
public ICollection<int> Collection { get; set; }
|
||||
public EmployeeReference Employee { get; set; }
|
||||
public object Random { get; set; }
|
||||
|
||||
public DictionaryInterfaceClass()
|
||||
{
|
||||
Dictionary = new Dictionary<string, int>
|
||||
{
|
||||
{ "existing", 1 }
|
||||
};
|
||||
Collection = new List<int>
|
||||
{
|
||||
1,
|
||||
2,
|
||||
3
|
||||
};
|
||||
Employee = new EmployeeReference
|
||||
{
|
||||
Name = "EmployeeName!"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// What types of events are there? Just sticking to a basic set of four for now.
|
||||
/// </summary>
|
||||
/// <remarks></remarks>
|
||||
public enum EventType
|
||||
{
|
||||
Debug = 0,
|
||||
Info = 1,
|
||||
Warning = 2,
|
||||
Error = 3
|
||||
}
|
||||
|
||||
public sealed class Event
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// If no current user is specified, returns Nothing (0 from VB)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks></remarks>
|
||||
private static int GetCurrentUserId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets either the application path or the current stack trace.
|
||||
/// NOTE: You MUST call this from the top level entry point. Otherwise,
|
||||
/// the stack trace will be buried in Logger itself.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks></remarks>
|
||||
private static string GetCurrentSubLocation()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
private string _sublocation;
|
||||
private int _userId;
|
||||
private EventType _type;
|
||||
private string _summary;
|
||||
private string _details;
|
||||
private string _stackTrace;
|
||||
private string _tag;
|
||||
private DateTime _time;
|
||||
|
||||
public Event(string summary)
|
||||
{
|
||||
_summary = summary;
|
||||
_time = DateTime.Now;
|
||||
|
||||
if (_userId == 0) _userId = GetCurrentUserId();
|
||||
//This call only works at top level for now.
|
||||
//If _stackTrace = Nothing Then _stackTrace = Environment.StackTrace
|
||||
if (_sublocation == null) _sublocation = GetCurrentSubLocation();
|
||||
}
|
||||
|
||||
public Event(string sublocation, int userId, EventType type, string summary, string details, string stackTrace, string tag)
|
||||
{
|
||||
_sublocation = sublocation;
|
||||
_userId = userId;
|
||||
_type = type;
|
||||
_summary = summary;
|
||||
_details = details;
|
||||
_stackTrace = stackTrace;
|
||||
_tag = tag;
|
||||
_time = DateTime.Now;
|
||||
|
||||
if (_userId == 0) _userId = GetCurrentUserId();
|
||||
//If _stackTrace = Nothing Then _stackTrace = Environment.StackTrace
|
||||
if (_sublocation == null) _sublocation = GetCurrentSubLocation();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{{ sublocation = {0}, userId = {1}, type = {2}, summary = {3}, details = {4}, stackTrace = {5}, tag = {6} }}", _sublocation, _userId, _type, _summary, _details, _stackTrace, _tag);
|
||||
}
|
||||
|
||||
public string sublocation
|
||||
{
|
||||
get { return _sublocation; }
|
||||
set { _sublocation = value; }
|
||||
}
|
||||
public int userId
|
||||
{
|
||||
get { return _userId; }
|
||||
set { _userId = value; }
|
||||
}
|
||||
public EventType type
|
||||
{
|
||||
get { return _type; }
|
||||
set { _type = value; }
|
||||
}
|
||||
public string summary
|
||||
{
|
||||
get { return _summary; }
|
||||
set { _summary = value; }
|
||||
}
|
||||
public string details
|
||||
{
|
||||
get { return _details; }
|
||||
set { _details = value; }
|
||||
}
|
||||
public string stackTrace
|
||||
{
|
||||
get { return _stackTrace; }
|
||||
set { _stackTrace = value; }
|
||||
}
|
||||
public string tag
|
||||
{
|
||||
get { return _tag; }
|
||||
set { _tag = value; }
|
||||
}
|
||||
public DateTime time
|
||||
{
|
||||
get { return _time; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class GoogleMapGeocoderStructure
|
||||
{
|
||||
public string Name;
|
||||
public Status Status;
|
||||
public List<Placemark> Placemark;
|
||||
}
|
||||
|
||||
public class Status
|
||||
{
|
||||
public string Request;
|
||||
public string Code;
|
||||
}
|
||||
|
||||
public class Placemark
|
||||
{
|
||||
public string Address;
|
||||
public AddressDetails AddressDetails;
|
||||
public Point Point;
|
||||
}
|
||||
|
||||
public class AddressDetails
|
||||
{
|
||||
public int Accuracy;
|
||||
public Country Country;
|
||||
}
|
||||
|
||||
public class Country
|
||||
{
|
||||
public string CountryNameCode;
|
||||
public AdministrativeArea AdministrativeArea;
|
||||
}
|
||||
|
||||
public class AdministrativeArea
|
||||
{
|
||||
public string AdministrativeAreaName;
|
||||
public SubAdministrativeArea SubAdministrativeArea;
|
||||
}
|
||||
|
||||
public class SubAdministrativeArea
|
||||
{
|
||||
public string SubAdministrativeAreaName;
|
||||
public Locality Locality;
|
||||
}
|
||||
|
||||
public class Locality
|
||||
{
|
||||
public string LocalityName;
|
||||
public Thoroughfare Thoroughfare;
|
||||
public PostalCode PostalCode;
|
||||
}
|
||||
|
||||
public class Thoroughfare
|
||||
{
|
||||
public string ThoroughfareName;
|
||||
}
|
||||
|
||||
public class PostalCode
|
||||
{
|
||||
public string PostalCodeNumber;
|
||||
}
|
||||
|
||||
public class Point
|
||||
{
|
||||
public List<decimal> Coordinates;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class Co : ICo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public interface ICo
|
||||
{
|
||||
string Name { get; set; }
|
||||
}
|
||||
|
||||
public interface IInterfacePropertyTestClass
|
||||
{
|
||||
ICo co { get; set; }
|
||||
}
|
||||
|
||||
public class InterfacePropertyTestClass : IInterfacePropertyTestClass
|
||||
{
|
||||
public ICo co { get; set; }
|
||||
|
||||
public InterfacePropertyTestClass()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class JsonPropertyClass
|
||||
{
|
||||
[JsonProperty("pie")]
|
||||
public string Pie = "Yum";
|
||||
|
||||
[JsonIgnore]
|
||||
public string pie = "No pie for you!";
|
||||
|
||||
public string pie1 = "PieChart!";
|
||||
|
||||
private int _sweetCakesCount;
|
||||
|
||||
[JsonProperty("sweet_cakes_count")]
|
||||
public int SweetCakesCount
|
||||
{
|
||||
get { return _sweetCakesCount; }
|
||||
set { _sweetCakesCount = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class ListErrorObject
|
||||
{
|
||||
public string Member { get; set; }
|
||||
|
||||
private string _throwError;
|
||||
public string ThrowError
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_throwError != null)
|
||||
return _throwError;
|
||||
|
||||
throw new Exception("ListErrorObject.ThrowError get error!");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && value.StartsWith("Handle"))
|
||||
{
|
||||
_throwError = value;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception("ListErrorObject.ThrowError set error!");
|
||||
}
|
||||
}
|
||||
|
||||
public string Member2 { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class ListErrorObjectCollection : Collection<ListErrorObject>
|
||||
{
|
||||
[OnError]
|
||||
internal void OnErrorMethod(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class ListTestClass
|
||||
{
|
||||
[JsonProperty]
|
||||
public string id { get; set; }
|
||||
[JsonProperty]
|
||||
public List<ListItem> items { get; set; }
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class ListItem
|
||||
{
|
||||
[JsonProperty]
|
||||
public string id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class LogEntry
|
||||
{
|
||||
public string Details { get; set; }
|
||||
public DateTime LogDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class NonRequest
|
||||
{
|
||||
public Guid Sid { get; set; }
|
||||
public Guid Uid { get; set; }
|
||||
public IList<string> FidOrder { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class ObjectArrayPropertyTest
|
||||
{
|
||||
public string Action { get; set; }
|
||||
public string Method { get; set; }
|
||||
public object[] Data { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PropertyCase
|
||||
{
|
||||
public string firstName { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string lastName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class RequestOnly
|
||||
{
|
||||
public string Request { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public enum RoleTransferOperation
|
||||
{
|
||||
First,
|
||||
Second
|
||||
}
|
||||
|
||||
public enum RoleTransferDirection
|
||||
{
|
||||
First,
|
||||
Second
|
||||
}
|
||||
|
||||
public class RoleTransfer
|
||||
{
|
||||
public RoleTransferOperation Operation { get; set; } //This is enum type
|
||||
public string RoleName { get; set; }
|
||||
public RoleTransferDirection Direction { get; set; } //This is enum type
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class SetOnlyPropertyClass2
|
||||
{
|
||||
private object _value;
|
||||
public object SetOnlyProperty
|
||||
{
|
||||
set { _value = value; }
|
||||
}
|
||||
public object GetValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class SubKlass : SuperKlass
|
||||
{
|
||||
public string SubProp { get; set; }
|
||||
public SubKlass(string subprop) { SubProp = subprop; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class SuperKlass
|
||||
{
|
||||
public string SuperProp { get; set; }
|
||||
public SuperKlass() { SuperProp = "default superprop"; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class VersionKeyedCollection : KeyedCollection<string, Person>, IList
|
||||
{
|
||||
public List<string> Messages { get; set; }
|
||||
|
||||
public VersionKeyedCollection()
|
||||
{
|
||||
Messages = new List<string>();
|
||||
}
|
||||
|
||||
protected override string GetKeyForItem(Person item)
|
||||
{
|
||||
return item.Name;
|
||||
}
|
||||
|
||||
[OnError]
|
||||
internal void OnErrorMethod(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
Messages.Add("Error message for member " + errorContext.Member + " = " + errorContext.Error.Message);
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
|
||||
object IList.this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index % 2 == 0)
|
||||
throw new Exception("Index even: " + index);
|
||||
|
||||
return this[index];
|
||||
}
|
||||
set { this[index] = (Person)value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,17 @@ using Newtonsoft.Json.Utilities;
|
||||
|
||||
namespace Newtonsoft.Json.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an Entity Framework EntityKey to and from JSON.
|
||||
/// </summary>
|
||||
public class EntityKeyMemberConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
EntityKeyMember entityKeyMember = (EntityKeyMember) value;
|
||||
@@ -77,6 +86,13 @@ namespace Newtonsoft.Json.Converters
|
||||
throw new JsonSerializationException("Unexpected end.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
/// <returns>The object value.</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||
{
|
||||
EntityKeyMember entityKeyMember = new EntityKeyMember();
|
||||
@@ -100,6 +116,13 @@ namespace Newtonsoft.Json.Converters
|
||||
return entityKeyMember;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(EntityKeyMember).IsAssignableFrom(objectType);
|
||||
|
||||
@@ -603,7 +603,7 @@ namespace Newtonsoft.Json
|
||||
/// <summary>
|
||||
/// Deserializes the JSON string to the specified type.
|
||||
/// </summary>
|
||||
/// <param name="value">The object to deserialize.</param>
|
||||
/// <param name="value">The JSON to deserialize.</param>
|
||||
/// <param name="type">The type of the object to deserialize.</param>
|
||||
/// <param name="settings">
|
||||
/// The <see cref="JsonSerializerSettings"/> used to deserialize the object.
|
||||
@@ -628,12 +628,26 @@ namespace Newtonsoft.Json
|
||||
return deserializedValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the object with values from the JSON string.
|
||||
/// </summary>
|
||||
/// <param name="value">The JSON to populate values from.</param>
|
||||
/// <param name="target">The target object to populate values onto.</param>
|
||||
public static void PopulateObject(string value, object target)
|
||||
{
|
||||
PopulateObject(value, target, null);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Populates the object with values from the JSON string.
|
||||
/// </summary>
|
||||
/// <param name="value">The JSON to populate values from.</param>
|
||||
/// <param name="target">The target object to populate values onto.</param>
|
||||
/// <param name="settings">
|
||||
/// The <see cref="JsonSerializerSettings"/> used to deserialize the object.
|
||||
/// If this is null, default serialization settings will be is used.
|
||||
/// </param>
|
||||
public static void PopulateObject(string value, object target, JsonSerializerSettings settings)
|
||||
{
|
||||
StringReader sr = new StringReader(value);
|
||||
|
||||
@@ -97,13 +97,21 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
protected virtual void OnAddingNew(AddingNewEventArgs e)
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:AddingNew"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The <see cref="AddingNewEventArgs"/> instance containing the event data.</param>
|
||||
protected virtual void OnAddingNew(AddingNewEventArgs e)
|
||||
{
|
||||
AddingNewEventHandler handler = AddingNew;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:ListChanged"/> event.
|
||||
/// </summary>
|
||||
/// <param name="e">The <see cref="ListChangedEventArgs"/> instance containing the event data.</param>
|
||||
protected virtual void OnListChanged(ListChangedEventArgs e)
|
||||
{
|
||||
ListChangedEventHandler handler = ListChanged;
|
||||
|
||||
@@ -462,6 +462,10 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:PropertyChanged"/> event with the provided arguments.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
@@ -469,6 +473,10 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:PropertyChanging"/> event with the provided arguments.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">Name of the property.</param>
|
||||
protected virtual void OnPropertyChanging(string propertyName)
|
||||
{
|
||||
if (PropertyChanging != null)
|
||||
|
||||
@@ -153,6 +153,12 @@ namespace Newtonsoft.Json.Linq
|
||||
throw new Exception("Cannot add or remove items from {0}.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of the child tokens of this token, in document order.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="IEnumerable{T}"/> of <see cref="JToken"/> containing the child tokens of this <see cref="JToken"/>, in document order.
|
||||
/// </returns>
|
||||
public override JEnumerable<JToken> Children()
|
||||
{
|
||||
return new JEnumerable<JToken>(ChildrenInternal());
|
||||
|
||||
@@ -365,6 +365,12 @@ namespace Newtonsoft.Json.Linq
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serves as a hash function for a particular type.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A hash code for the current <see cref="T:System.Object"/>.
|
||||
/// </returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
if (_value == null)
|
||||
|
||||
@@ -148,6 +148,7 @@
|
||||
<Compile Include="Serialization\JsonSerializerProxy.cs" />
|
||||
<Compile Include="Serialization\JsonTypeReflector.cs" />
|
||||
<Compile Include="Serialization\OnErrorAttribute.cs" />
|
||||
<Compile Include="StreamingContext.cs" />
|
||||
<Compile Include="TypeNameHandling.cs" />
|
||||
<Compile Include="Utilities\BidirectionalDictionary.cs" />
|
||||
<Compile Include="Utilities\ConvertUtils.cs" />
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
<Compile Include="Serialization\DefaultContractResolver.cs" />
|
||||
<Compile Include="Serialization\DefaultReferenceResolver.cs" />
|
||||
<Compile Include="Serialization\DefaultSerializationBinder.cs" />
|
||||
<Compile Include="Serialization\ErrorContext.cs" />
|
||||
<Compile Include="Serialization\IContractResolver.cs" />
|
||||
<Compile Include="Serialization\IReferenceResolver.cs" />
|
||||
<Compile Include="Serialization\JsonArrayContract.cs" />
|
||||
@@ -124,6 +125,8 @@
|
||||
<Compile Include="Serialization\JsonSerializerProxy.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerInternalReader.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerInternalWriter.cs" />
|
||||
<Compile Include="Serialization\OnErrorAttribute.cs" />
|
||||
<Compile Include="StreamingContext.cs" />
|
||||
<Compile Include="TypeNameHandling.cs" />
|
||||
<Compile Include="Utilities\BidirectionalDictionary.cs" />
|
||||
<Compile Include="Utilities\CollectionUtils.cs" />
|
||||
|
||||
@@ -161,12 +161,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
|
||||
{
|
||||
Type prevAttributeType = null;
|
||||
ParameterInfo[] parameters = method.GetParameters();
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), contract.OnSerializing, ref prevAttributeType))
|
||||
{
|
||||
contract.OnSerializing = method;
|
||||
@@ -183,12 +183,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
contract.OnDeserialized = method;
|
||||
}
|
||||
#endif
|
||||
if (IsValidCallback(method, parameters, typeof(OnErrorAttribute), contract.OnError, ref prevAttributeType))
|
||||
{
|
||||
contract.OnError = method;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -235,7 +235,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
return CreateObjectContract(objectType);
|
||||
}
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
private static bool IsValidCallback(MethodInfo method, ParameterInfo[] parameters, Type attributeType, MethodInfo currentCallback, ref Type prevAttributeType)
|
||||
{
|
||||
if (!method.IsDefined(attributeType, false))
|
||||
@@ -268,7 +267,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static string GetClrTypeFullName(Type type)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -64,5 +63,4 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// <value><c>true</c> if handled; otherwise, <c>false</c>.</value>
|
||||
public bool Handled { get; set; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -46,10 +46,10 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// <value>Whether this type contract is serialized as a reference.</value>
|
||||
public bool? IsReference { get; set; }
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT
|
||||
private static readonly StreamingContext SerializationStreamingContextParameter = new StreamingContext(StreamingContextStates.All);
|
||||
private static readonly object[] SerializationEventParameterValues = new object[] { SerializationStreamingContextParameter };
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Gets or sets the method called immediately after deserialization of the object.
|
||||
/// </summary>
|
||||
@@ -70,10 +70,14 @@ namespace Newtonsoft.Json.Serialization
|
||||
/// </summary>
|
||||
/// <value>The method called before serialization of the object.</value>
|
||||
public MethodInfo OnSerializing { get; set; }
|
||||
|
||||
public MethodInfo OnError { get; set; }
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the method called when an error is thrown during the serialization of the object.
|
||||
/// </summary>
|
||||
/// <value>The method called when an error is thrown during the serialization of the object.</value>
|
||||
public MethodInfo OnError { get; set; }
|
||||
|
||||
internal void InvokeOnSerializing(object o)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT
|
||||
@@ -106,13 +110,11 @@ namespace Newtonsoft.Json.Serialization
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
internal void InvokeOnError(object o, ErrorContext errorContext)
|
||||
{
|
||||
if (OnError != null)
|
||||
OnError.Invoke(o, new object[] { SerializationStreamingContextParameter, errorContext });
|
||||
}
|
||||
#endif
|
||||
|
||||
internal JsonContract(Type underlyingType)
|
||||
{
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
internal abstract class JsonSerializerInternalBase
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
private ErrorContext _currentErrorContext;
|
||||
|
||||
protected ErrorContext GetErrorContext(object originalObject, object member, Exception error)
|
||||
@@ -52,6 +51,5 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
_currentErrorContext = null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -465,14 +465,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
ErrorContext errorContext = GetErrorContext(dictionary.UnderlyingDictionary, keyValue, ex);
|
||||
contract.InvokeOnError(dictionary.UnderlyingDictionary, errorContext);
|
||||
|
||||
if (errorContext.Handled)
|
||||
HandleError(reader, initialDepth);
|
||||
else
|
||||
#endif
|
||||
throw;
|
||||
}
|
||||
break;
|
||||
@@ -498,9 +496,9 @@ namespace Newtonsoft.Json.Serialization
|
||||
#if !PocketPC && !SILVERLIGHT
|
||||
if (contract.OnSerializing != null && isTemporaryListReference)
|
||||
throw new JsonSerializationException("Cannot call OnSerializing on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
|
||||
#endif
|
||||
if (contract.OnError != null && isTemporaryListReference)
|
||||
throw new JsonSerializationException("Cannot call OnError on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
|
||||
#endif
|
||||
|
||||
PopulateList(CollectionUtils.CreateCollectionWrapper(l), reader, reference, contract);
|
||||
});
|
||||
@@ -536,14 +534,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
ErrorContext errorContext = GetErrorContext(list, wrappedList.Count, ex);
|
||||
contract.InvokeOnError(list, errorContext);
|
||||
|
||||
if (errorContext.Handled)
|
||||
HandleError(reader, initialDepth);
|
||||
else
|
||||
#endif
|
||||
throw;
|
||||
}
|
||||
break;
|
||||
@@ -682,14 +678,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
ErrorContext errorContext = GetErrorContext(newObject, memberName, ex);
|
||||
contract.InvokeOnError(newObject, errorContext);
|
||||
|
||||
if (errorContext.Handled)
|
||||
HandleError(reader, initialDepth);
|
||||
else
|
||||
#endif
|
||||
throw;
|
||||
}
|
||||
break;
|
||||
@@ -734,7 +728,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
private void HandleError(JsonReader reader, int initialDepth)
|
||||
{
|
||||
ClearErrorContext();
|
||||
@@ -744,6 +737,5 @@ namespace Newtonsoft.Json.Serialization
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -296,14 +296,12 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
ErrorContext errorContext = GetErrorContext(value, property.Member.Name, ex);
|
||||
contract.InvokeOnError(value, errorContext);
|
||||
|
||||
if (errorContext.Handled)
|
||||
HandleError(writer, initialDepth);
|
||||
else
|
||||
#endif
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -403,15 +401,13 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
ErrorContext errorContext = GetErrorContext(values, i, ex);
|
||||
contract.InvokeOnError(values, errorContext);
|
||||
|
||||
if (errorContext.Handled)
|
||||
HandleError(writer, initialDepth);
|
||||
else
|
||||
#endif
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,15 +468,13 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
ErrorContext errorContext = GetErrorContext(values, propertyName, ex);
|
||||
contract.InvokeOnError(values, errorContext);
|
||||
|
||||
if (errorContext.Handled)
|
||||
HandleError(writer, initialDepth);
|
||||
else
|
||||
#endif
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,7 +484,6 @@ namespace Newtonsoft.Json.Serialization
|
||||
contract.InvokeOnSerialized(values);
|
||||
}
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
private void HandleError(JsonWriter writer, int initialDepth)
|
||||
{
|
||||
ClearErrorContext();
|
||||
@@ -500,6 +493,5 @@ namespace Newtonsoft.Json.Serialization
|
||||
writer.WriteEnd();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !PocketPC && !SILVERLIGHT && !NET20
|
||||
using System;
|
||||
|
||||
namespace Newtonsoft.Json.Serialization
|
||||
@@ -35,5 +34,4 @@ namespace Newtonsoft.Json.Serialization
|
||||
public sealed class OnErrorAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#if PocketPC || SILVERLIGHT
|
||||
#pragma warning disable 1591
|
||||
|
||||
// This class is... borrowed from .NET and Microsoft for a short time.
|
||||
// Hopefully Microsoft will add DateTimeOffset to the compact framework
|
||||
// or I will rewrite a striped down version of this file myself
|
||||
|
||||
namespace System.Runtime.Serialization
|
||||
{
|
||||
public enum StreamingContextStates
|
||||
{
|
||||
All = 255,
|
||||
Clone = 64,
|
||||
CrossAppDomain = 128,
|
||||
CrossMachine = 2,
|
||||
CrossProcess = 1,
|
||||
File = 4,
|
||||
Other = 32,
|
||||
Persistence = 8,
|
||||
Remoting = 16
|
||||
}
|
||||
|
||||
public struct StreamingContext
|
||||
{
|
||||
internal object m_additionalContext;
|
||||
internal StreamingContextStates m_state;
|
||||
public StreamingContext(StreamingContextStates state)
|
||||
: this(state, null)
|
||||
{
|
||||
}
|
||||
|
||||
public StreamingContext(StreamingContextStates state, object additional)
|
||||
{
|
||||
this.m_state = state;
|
||||
this.m_additionalContext = additional;
|
||||
}
|
||||
|
||||
public object Context
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_additionalContext;
|
||||
}
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return ((obj is StreamingContext) && ((((StreamingContext)obj).m_additionalContext == this.m_additionalContext) && (((StreamingContext)obj).m_state == this.m_state)));
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)this.m_state;
|
||||
}
|
||||
|
||||
public StreamingContextStates State
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user