diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index bf396675..5140c1f8 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -96,28 +96,6 @@ namespace Newtonsoft.Json.Tests.Serialization [TestFixture] public class JsonSerializerTest : TestFixtureBase { - public class ListSourceTest : IListSource - { - private string str; - - public string strprop - { - get { return str; } - set { str = value; } - } - - [JsonIgnore] - public bool ContainsListCollection - { - get { return false; } - } - - public IList GetList() - { - return new List(); - } - } - [Test] public void ListSourceSerialize() { @@ -132,18 +110,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("test", c2.strprop); } - public struct ImmutableStruct - { - public ImmutableStruct(string value) - { - Value = value; - Value2 = 0; - } - - public string Value { get; } - public int Value2 { get; set; } - } - [Test] public void DeserializeImmutableStruct() { @@ -174,11 +140,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(2, result.Value2); } - public class ErroringClass - { - public DateTime Tags { get; set; } - } - [Test] public void DontCloseInputOnDeserializeError() { @@ -213,65 +174,6 @@ namespace Newtonsoft.Json.Tests.Serialization } } - public interface ISubclassBase - { - int ID { get; set; } - string Name { get; set; } - bool P1 { get; } - } - - public interface ISubclass : ISubclassBase - { - new bool P1 { get; set; } - int P2 { get; set; } - } - - public interface IMainClass - { - int ID { get; set; } - string Name { get; set; } - ISubclass Subclass { get; set; } - } - - public class Subclass : ISubclass - { - public int ID { get; set; } - public string Name { get; set; } - public bool P1 { get; set; } - public int P2 { get; set; } - } - - public class MainClass : IMainClass - { - public int ID { get; set; } - public string Name { get; set; } - public ISubclass Subclass { get; set; } - } - - public class MyFactory - { - public static ISubclass InstantiateSubclass() - { - return new Subclass - { - ID = 123, - Name = "ABC", - P1 = true, - P2 = 44 - }; - } - - public static IMainClass InstantiateManiClass() - { - return new MainClass - { - ID = 567, - Name = "XYZ", - Subclass = InstantiateSubclass() - }; - } - } - [Test] public void SerializeInterfaceWithHiddenProperties() { @@ -316,21 +218,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("def", enumerableObject[1].Value); } - public class GenericIEnumerableWithImplicitConversion - { - public IEnumerable Enumerable { get; set; } - } - - public class ClassWithImplicitOperator - { - public string Value { get; set; } - - public static implicit operator ClassWithImplicitOperator(string value) - { - return new ClassWithImplicitOperator() { Value = value }; - } - } - #if !(PORTABLE || PORTABLE40 || NET20 || NET35) [Test] public void LargeIntegerAsString() @@ -341,11 +228,6 @@ namespace Newtonsoft.Json.Tests.Serialization var largeOddWorkingNumber = JsonConvert.DeserializeObject("{\"Blah\": 53443333222211111117 }"); Assert.AreEqual("53443333222211111117", largeOddWorkingNumber.Blah); } - - public class Foo64 - { - public string Blah { get; set; } - } #endif #if !NET20 @@ -483,21 +365,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(foo1.Bars[2], foo2.Bars[2]); } - public class FooRequired - { - [JsonProperty(Required = Required.Always)] - public List Bars { get; private set; } - - public FooRequired(IEnumerable bars) - { - Bars = new List(); - if (bars != null) - { - Bars.AddRange(bars); - } - } - } - [Test] public void CoercedEmptyStringWithRequired() { @@ -523,16 +390,6 @@ namespace Newtonsoft.Json.Tests.Serialization ExceptionAssert.Throws(() => { JsonConvert.DeserializeObject("{Bars:''}"); }, "Required property 'Bars' expects a value but got null. Path '', line 1, position 9."); } - public class IgnoredProperty - { - [JsonIgnore] - [JsonProperty(Required = Required.Always)] - public string StringProp1 { get; set; } - - [JsonIgnore] - public string StringProp2 { get; set; } - } - [Test] public void NoErrorWhenValueDoesNotMatchIgnoredProperty() { @@ -541,18 +398,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.IsNull(p.StringProp2); } - public class Binding - { - [JsonProperty(Required = Required.Always)] - public Binding RequiredProperty { get; set; } - } - - public class Binding_DisallowNull - { - [JsonProperty(Required = Required.DisallowNull)] - public Binding RequiredProperty { get; set; } - } - [Test] public void Serialize_Required_DisallowedNull() { @@ -569,35 +414,12 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("{}", json); } - [JsonObject(ItemRequired = Required.DisallowNull)] - public class DictionaryWithNoNull - { - public string Name { get; set; } - } - [Test] public void Serialize_ItemRequired_DisallowedNull() { ExceptionAssert.Throws(() => { JsonConvert.SerializeObject(new DictionaryWithNoNull()); }, "Cannot write a null value for property 'Name'. Property requires a non-null value. Path ''."); } - public class DictionaryKeyContractResolver : DefaultContractResolver - { - protected override string ResolveDictionaryKey(string dictionaryKey) - { - return dictionaryKey; - } - - protected override string ResolvePropertyName(string propertyName) - { -#if DNXCORE50 - return propertyName.ToUpperInvariant(); -#else - return propertyName.ToUpper(CultureInfo.InvariantCulture); -#endif - } - } - [Test] public void DictionaryKeyContractResolverTest() { @@ -659,18 +481,7 @@ namespace Newtonsoft.Json.Tests.Serialization "Unexpected end when deserializing object. Path 'key', line 1, position 8."); } - public class IncompleteTestClass - { - public int Key { get; set; } - } - #if !NET20 - public enum EnumA - { - [EnumMember(Value = "value_a")] - ValueA - } - [Test] public void DeserializeEnumsByName() { @@ -682,12 +493,6 @@ namespace Newtonsoft.Json.Tests.Serialization } #endif - public class RequiredPropertyTestClass - { - [JsonRequired] - internal string Name { get; set; } - } - [Test] public void RequiredPropertyTest() { @@ -719,17 +524,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("Name!", c3.Name); } - public class RequiredPropertyConstructorTestClass - { - public RequiredPropertyConstructorTestClass(string name) - { - Name = name; - } - - [JsonRequired] - internal string Name { get; set; } - } - [Test] public void RequiredPropertyConstructorTest() { @@ -754,34 +548,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual("Name!", c3.Name); } - public class IgnoredPropertiesTestClass - { - [JsonIgnore] - public Version IgnoredProperty { get; set; } - - [JsonIgnore] - public List IgnoredList { get; set; } - - [JsonIgnore] - public Dictionary IgnoredDictionary { get; set; } - - [JsonProperty(Required = Required.Always)] - public string Name { get; set; } - } - - public class IgnoredPropertiesContractResolver : DefaultContractResolver - { - public override JsonContract ResolveContract(Type type) - { - if (type == typeof(Version)) - { - throw new Exception("Error!"); - } - - return base.ResolveContract(type); - } - } - [Test] public void NeverResolveIgnoredPropertyTypes() { @@ -1014,15 +780,6 @@ namespace Newtonsoft.Json.Tests.Serialization } #endif - public class NullTestClass - { - public JObject Value1 { get; set; } - public JValue Value2 { get; set; } - public JRaw Value3 { get; set; } - public JToken Value4 { get; set; } - public object Value5 { get; set; } - } - [Test] public void DeserializeNullToJTokenProperty() { @@ -1040,24 +797,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.IsNull(otc.Value5); } - public class Link - { - /// - /// The unique identifier. - /// - public int Id; - - /// - /// The parent information identifier. - /// - public int ParentId; - - /// - /// The child information identifier. - /// - public int ChildId; - } - #if !(NET20 || NET35 || PORTABLE40 || PORTABLE) [Test] public void ReadIntegerWithError() @@ -1129,16 +868,6 @@ namespace Newtonsoft.Json.Tests.Serialization } #endif - public class BaseClass - { - internal bool IsTransient { get; set; } - } - - public class ChildClass : BaseClass - { - public new bool IsTransient { get; set; } - } - [Test] public void NewProperty() { @@ -1148,16 +877,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(true, childClass.IsTransient); } - public class BaseClassVirtual - { - internal virtual bool IsTransient { get; set; } - } - - public class ChildClassVirtual : BaseClassVirtual - { - public new virtual bool IsTransient { get; set; } - } - [Test] public void NewPropertyVirtual() { @@ -1167,37 +886,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(true, childClass.IsTransient); } - public class ResponseWithNewGenericProperty : SimpleResponse - { - public new T Data { get; set; } - } - - public class ResponseWithNewGenericPropertyVirtual : SimpleResponse - { - public new virtual T Data { get; set; } - } - - public class ResponseWithNewGenericPropertyOverride : ResponseWithNewGenericPropertyVirtual - { - public override T Data { get; set; } - } - - public abstract class SimpleResponse - { - public string Result { get; set; } - public string Message { get; set; } - public object Data { get; set; } - - protected SimpleResponse() - { - } - - protected SimpleResponse(string message) - { - Message = message; - } - } - [Test] public void CanSerializeWithBuiltInTypeAsGenericArgument() { @@ -1324,11 +1012,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.IsTrue(JToken.DeepEquals(o, JObject.Parse(json))); } - public class CommentTestObject - { - public bool? A { get; set; } - } - [Test] public void DeserializeCommentTestObjectWithComments() { @@ -1707,60 +1390,7 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(ratio.Denominator, ratio2.Denominator); Assert.AreEqual(ratio.Numerator, ratio2.Numerator); } - - public class PreserveReferencesCallbackTestObject : ISerializable - { - internal string _stringValue; - internal int _intValue; - internal PersonReference _person1; - internal PersonReference _person2; - internal PersonReference _person3; - internal PreserveReferencesCallbackTestObject _parent; - internal SerializationInfo _serializationInfo; - - public PreserveReferencesCallbackTestObject(string stringValue, int intValue, PersonReference p1, PersonReference p2, PersonReference p3) - { - _stringValue = stringValue; - _intValue = intValue; - _person1 = p1; - _person2 = p2; - _person3 = p3; - } - - protected PreserveReferencesCallbackTestObject(SerializationInfo info, StreamingContext context) - { - _serializationInfo = info; - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("stringValue", _stringValue); - info.AddValue("intValue", _intValue); - info.AddValue("person1", _person1, typeof(PersonReference)); - info.AddValue("person2", _person2, typeof(PersonReference)); - info.AddValue("person3", _person3, typeof(PersonReference)); - info.AddValue("parent", _parent, typeof(PreserveReferencesCallbackTestObject)); - } - - [OnDeserialized] - private void OnDeserializedMethod(StreamingContext context) - { - if (_serializationInfo == null) - { - return; - } - - _stringValue = _serializationInfo.GetString("stringValue"); - _intValue = _serializationInfo.GetInt32("intValue"); - _person1 = (PersonReference)_serializationInfo.GetValue("person1", typeof(PersonReference)); - _person2 = (PersonReference)_serializationInfo.GetValue("person2", typeof(PersonReference)); - _person3 = (PersonReference)_serializationInfo.GetValue("person3", typeof(PersonReference)); - _parent = (PreserveReferencesCallbackTestObject)_serializationInfo.GetValue("parent", typeof(PreserveReferencesCallbackTestObject)); - - _serializationInfo = null; - } - } - + [Test] public void PreserveReferencesCallbackTest() { @@ -1876,28 +1506,6 @@ namespace Newtonsoft.Json.Tests.Serialization // be used when serializing and deserializing the object, // resulting in unexpected behavior during serialization and deserialization. - public class Foo1 - { - public object foo { get; set; } - } - - public class Bar1 - { - public object bar { get; set; } - } - - public class Foo1 : Foo1 - { - public new T foo { get; set; } - - public T foo2 { get; set; } - } - - public class FooBar1 : Foo1 - { - public new Bar1 foo { get; set; } - } - [Test] public void BaseClassSerializesAsExpected() { @@ -1977,51 +1585,7 @@ namespace Newtonsoft.Json.Tests.Serialization stopWatch.Stop(); } - internal class DictionaryKeyCast - { - private String _name; - private int _number; - - public DictionaryKeyCast(String name, int number) - { - _name = name; - _number = number; - } - - public override string ToString() - { - return _name + " " + _number; - } - - public static implicit operator DictionaryKeyCast(string dictionaryKey) - { - var strings = dictionaryKey.Split(' '); - return new DictionaryKeyCast(strings[0], Convert.ToInt32(strings[1])); - } - } - #if !(NET20 || NET35) - [DataContract] - public class BaseDataContractWithHidden - { - [DataMember(Name = "virtualMember")] - public virtual string VirtualMember { get; set; } - - [DataMember(Name = "nonVirtualMember")] - public string NonVirtualMember { get; set; } - - public virtual object NewMember { get; set; } - } - - public class ChildDataContractWithHidden : BaseDataContractWithHidden - { - [DataMember(Name = "NewMember")] - public new virtual string NewMember { get; set; } - - public override string VirtualMember { get; set; } - public string AddedMember { get; set; } - } - [Test] public void ChildDataContractTestWithHidden() { @@ -2036,87 +1600,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(@"{""NewMember"":""NewMember!"",""virtualMember"":""VirtualMember!"",""nonVirtualMember"":""NonVirtualMember!""}", result); } - // ignore hiding members compiler warning -#pragma warning disable 108, 114 - [DataContract] - public class BaseWithContract - { - [DataMember(Name = "VirtualWithDataMemberBase")] - public virtual string VirtualWithDataMember { get; set; } - - [DataMember] - public virtual string Virtual { get; set; } - - [DataMember(Name = "WithDataMemberBase")] - public string WithDataMember { get; set; } - - [DataMember] - public string JustAProperty { get; set; } - } - - [DataContract] - public class BaseWithoutContract - { - [DataMember(Name = "VirtualWithDataMemberBase")] - public virtual string VirtualWithDataMember { get; set; } - - [DataMember] - public virtual string Virtual { get; set; } - - [DataMember(Name = "WithDataMemberBase")] - public string WithDataMember { get; set; } - - [DataMember] - public string JustAProperty { get; set; } - } - - [DataContract] - public class SubWithoutContractNewProperties : BaseWithContract - { - [DataMember(Name = "VirtualWithDataMemberSub")] - public string VirtualWithDataMember { get; set; } - - public string Virtual { get; set; } - - [DataMember(Name = "WithDataMemberSub")] - public string WithDataMember { get; set; } - - public string JustAProperty { get; set; } - } - - [DataContract] - public class SubWithoutContractVirtualProperties : BaseWithContract - { - public override string VirtualWithDataMember { get; set; } - - [DataMember(Name = "VirtualSub")] - public override string Virtual { get; set; } - } - - [DataContract] - public class SubWithContractNewProperties : BaseWithContract - { - [DataMember(Name = "VirtualWithDataMemberSub")] - public string VirtualWithDataMember { get; set; } - - [DataMember(Name = "Virtual2")] - public string Virtual { get; set; } - - [DataMember(Name = "WithDataMemberSub")] - public string WithDataMember { get; set; } - - [DataMember(Name = "JustAProperty2")] - public string JustAProperty { get; set; } - } - - [DataContract] - public class SubWithContractVirtualProperties : BaseWithContract - { - [DataMember(Name = "VirtualWithDataMemberSub")] - public virtual string VirtualWithDataMember { get; set; } - } -#pragma warning restore 108, 114 - [Test] public void SubWithoutContractNewPropertiesTest() { @@ -2916,11 +2399,6 @@ keyword such as type of business."" Assert.AreEqual(StringComparison.CurrentCultureIgnoreCase, s); } - public class ClassWithTimeSpan - { - public TimeSpan TimeSpanField; - } - [Test] public void TimeSpanTest() { @@ -3514,19 +2992,6 @@ keyword such as type of business."" Assert.AreEqual("lastName", o.lastName); } - public sealed class ConstructorAndDefaultValueAttributeTestClass - { - public ConstructorAndDefaultValueAttributeTestClass(string testProperty1) - { - TestProperty1 = testProperty1; - } - - public string TestProperty1 { get; set; } - - [DefaultValue(21)] - public int TestProperty2 { get; set; } - } - [Test] public void PopulateDefaultValueWhenUsingConstructor() { @@ -3547,19 +3012,6 @@ keyword such as type of business."" Assert.AreEqual(21, c.TestProperty2); } - public sealed class ConstructorAndRequiredTestClass - { - public ConstructorAndRequiredTestClass(string testProperty1) - { - TestProperty1 = testProperty1; - } - - public string TestProperty1 { get; set; } - - [JsonProperty(Required = Required.AllowNull)] - public int TestProperty2 { get; set; } - } - [Test] public void RequiredWhenUsingConstructor() { @@ -3751,42 +3203,6 @@ keyword such as type of business."" #endif #if !NET20 - [DataContract] - public class DataContractPrivateMembers - { - public DataContractPrivateMembers() - { - } - - public DataContractPrivateMembers(string name, int age, int rank, string title) - { - _name = name; - Age = age; - Rank = rank; - Title = title; - } - - [DataMember] - private string _name; - - [DataMember(Name = "_age")] - private int Age { get; set; } - - [JsonProperty] - private int Rank { get; set; } - - [JsonProperty(PropertyName = "JsonTitle")] - [DataMember(Name = "DataTitle")] - private string Title { get; set; } - - public string NotIncluded { get; set; } - - public override string ToString() - { - return "_name: " + _name + ", _age: " + Age + ", Rank: " + Rank + ", JsonTitle: " + Title; - } - } - [Test] public void SerializeDataContractPrivateMembers() { @@ -4499,24 +3915,6 @@ Path '', line 1, position 1."); Assert.AreEqual(wagePerson.HourlyWage, ((WagePerson)newPersonPropertyClass.Person).HourlyWage); } - public class ExistingValueClass - { - public Dictionary Dictionary { get; set; } - public List List { get; set; } - - public ExistingValueClass() - { - Dictionary = new Dictionary - { - { "existing", "yup" } - }; - List = new List - { - "existing" - }; - } - } - [Test] public void DeserializePopulateDictionaryAndList() { @@ -4533,73 +3931,6 @@ Path '', line 1, position 1."); Assert.AreEqual("existing", d.List[0]); } - public interface IKeyValueId - { - int Id { get; set; } - string Key { get; set; } - string Value { get; set; } - } - - public class KeyValueId : IKeyValueId - { - public int Id { get; set; } - public string Key { get; set; } - public string Value { get; set; } - } - - public class ThisGenericTest where T : IKeyValueId - { - private Dictionary _dict1 = new Dictionary(); - - public string MyProperty { get; set; } - - public void Add(T item) - { - _dict1.Add(item.Key, item); - } - - public T this[string key] - { - get { return _dict1[key]; } - set { _dict1[key] = value; } - } - - public T this[int id] - { - get { return _dict1.Values.FirstOrDefault(x => x.Id == id); } - set - { - var item = this[id]; - - if (item == null) - { - Add(value); - } - else - { - _dict1[item.Key] = value; - } - } - } - - public string ToJson() - { - return JsonConvert.SerializeObject(this, Formatting.Indented); - } - - public T[] TheItems - { - get { return _dict1.Values.ToArray(); } - set - { - foreach (var item in value) - { - Add(item); - } - } - } - } - [Test] public void IgnoreIndexedProperties() { @@ -4632,11 +3963,6 @@ Path '', line 1, position 1."); Assert.AreEqual("some value", gen.MyProperty); } - public class JRawValueTestObject - { - public JRaw Value { get; set; } - } - [Test] public void JRawValue() { @@ -4669,52 +3995,7 @@ Path '', line 1, position 1."); { PreserveReferencesHandling = PreserveReferencesHandling.All, MetadataPropertyHandling = MetadataPropertyHandling.Default - }), "Cannot preserve reference to readonly dictionary, or dictionary created from a non-default constructor: Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+DictionaryWithNoDefaultConstructor. Path 'key1', line 1, position 16."); - } - - public class DictionaryWithNoDefaultConstructor : Dictionary - { - public DictionaryWithNoDefaultConstructor(IEnumerable> initial) - { - foreach (KeyValuePair pair in initial) - { - Add(pair.Key, pair.Value); - } - } - } - - [JsonObject(MemberSerialization.OptIn)] - public class A - { - [JsonProperty("A1")] - private string _A1; - - public string A1 - { - get { return _A1; } - set { _A1 = value; } - } - - [JsonProperty("A2")] - private string A2 { get; set; } - } - - [JsonObject(MemberSerialization.OptIn)] - public class B : A - { - public string B1 { get; set; } - - [JsonProperty("B2")] - private string _B2; - - public string B2 - { - get { return _B2; } - set { _B2 = value; } - } - - [JsonProperty("B3")] - private string B3 { get; set; } + }), "Cannot preserve reference to readonly dictionary, or dictionary created from a non-default constructor: Newtonsoft.Json.Tests.TestObjects.DictionaryWithNoDefaultConstructor. Path 'key1', line 1, position 16."); } [Test] @@ -9993,7 +9274,9 @@ This is just junk, though."; }, "Cannot populate list type System.Net.Mime.HeaderCollection. Path 'Headers', line 26, position 14."); } +#endif +#if !(DNXCORE50) public class MailAddressReadConverter : JsonConverter { public override bool CanConvert(Type objectType) diff --git a/Src/Newtonsoft.Json.Tests/Serialization/ShouldSerializeTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/ShouldSerializeTests.cs index 1b4a3942..ec4e3cf0 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/ShouldSerializeTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/ShouldSerializeTests.cs @@ -75,10 +75,10 @@ namespace Newtonsoft.Json.Tests.Serialization [Test] public void VirtualShouldSerialize() { - var setFoo = new Foo1() + var setFoo = new Foo2() { name = Guid.NewGuid().ToString(), - myBar = new Bar1() + myBar = new Bar2() { name = Guid.NewGuid().ToString(), myBaz = new Baz1[] @@ -112,7 +112,7 @@ namespace Newtonsoft.Json.Tests.Serialization }; var setFooJson = Serialize(setFoo); - var deserializedSetFoo = JsonConvert.DeserializeObject(setFooJson); + var deserializedSetFoo = JsonConvert.DeserializeObject(setFooJson); Assert.AreEqual(setFoo.name, deserializedSetFoo.name); Assert.IsNotNull(deserializedSetFoo.myBar); @@ -132,7 +132,7 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(true, setFoo.myBar.ShouldSerializemyBazCalled); } - private string Serialize(Foo1 f) + private string Serialize(Foo2 f) { //Code copied from JsonConvert.SerializeObject(), with addition of trace writing JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(); @@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Tests.Serialization using (JsonTextWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.None; - jsonSerializer.Serialize(jsonWriter, f, typeof(Foo1)); + jsonSerializer.Serialize(jsonWriter, f, typeof(Foo2)); } return sw.ToString(); @@ -513,11 +513,11 @@ namespace Newtonsoft.Json.Tests.Serialization } } - public class Foo1 + public class Foo2 { - private Bar1 myBarField; + private Bar2 myBarField; - public Bar1 myBar + public Bar2 myBar { get { return myBarField; } set { myBarField = value; } @@ -542,7 +542,7 @@ namespace Newtonsoft.Json.Tests.Serialization } } - public class Bar1 + public class Bar2 { [JsonIgnore] public bool ShouldSerializemyBazCalled { get; set; } diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/A.cs b/Src/Newtonsoft.Json.Tests/TestObjects/A.cs new file mode 100644 index 00000000..1372e973 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/A.cs @@ -0,0 +1,43 @@ +#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 +{ + [JsonObject(MemberSerialization.OptIn)] + public class A + { + [JsonProperty("A1")] + private string _A1; + + public string A1 + { + get { return _A1; } + set { _A1 = value; } + } + + [JsonProperty("A2")] + private string A2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/B.cs b/Src/Newtonsoft.Json.Tests/TestObjects/B.cs new file mode 100644 index 00000000..aafc5ea9 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/B.cs @@ -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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.OptIn)] + public class B : A + { + public string B1 { get; set; } + + [JsonProperty("B2")] + private string _B2; + + public string B2 + { + get { return _B2; } + set { _B2 = value; } + } + + [JsonProperty("B3")] + private string B3 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Bar1.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Bar1.cs new file mode 100644 index 00000000..39bea169 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Bar1.cs @@ -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 Bar1 + { + public object bar { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseClass.cs new file mode 100644 index 00000000..d320c82b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseClass.cs @@ -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 BaseClass + { + internal bool IsTransient { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseClassVirtual.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseClassVirtual.cs new file mode 100644 index 00000000..fd039ee7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseClassVirtual.cs @@ -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 BaseClassVirtual + { + internal virtual bool IsTransient { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContractWithHidden.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContractWithHidden.cs new file mode 100644 index 00000000..3bbd35df --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContractWithHidden.cs @@ -0,0 +1,43 @@ +#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 + +#if !NET20 +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [DataContract] + public class BaseDataContractWithHidden + { + [DataMember(Name = "virtualMember")] + public virtual string VirtualMember { get; set; } + + [DataMember(Name = "nonVirtualMember")] + public string NonVirtualMember { get; set; } + + public virtual object NewMember { get; set; } + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithContract.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithContract.cs new file mode 100644 index 00000000..a69b3e64 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithContract.cs @@ -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 + +#if !NET20 +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [DataContract] + public class BaseWithContract + { + [DataMember(Name = "VirtualWithDataMemberBase")] + public virtual string VirtualWithDataMember { get; set; } + + [DataMember] + public virtual string Virtual { get; set; } + + [DataMember(Name = "WithDataMemberBase")] + public string WithDataMember { get; set; } + + [DataMember] + public string JustAProperty { get; set; } + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithoutContract.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithoutContract.cs new file mode 100644 index 00000000..452f9e26 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithoutContract.cs @@ -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 + +#if !NET20 +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [DataContract] + public class BaseWithoutContract + { + [DataMember(Name = "VirtualWithDataMemberBase")] + public virtual string VirtualWithDataMember { get; set; } + + [DataMember] + public virtual string Virtual { get; set; } + + [DataMember(Name = "WithDataMemberBase")] + public string WithDataMember { get; set; } + + [DataMember] + public string JustAProperty { get; set; } + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Binding.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Binding.cs new file mode 100644 index 00000000..295863cf --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Binding.cs @@ -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 Binding + { + [JsonProperty(Required = Required.Always)] + public Binding RequiredProperty { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Binding_DisallowNull.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Binding_DisallowNull.cs new file mode 100644 index 00000000..632c18ae --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Binding_DisallowNull.cs @@ -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 Binding_DisallowNull + { + [JsonProperty(Required = Required.DisallowNull)] + public Binding RequiredProperty { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ChildClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ChildClass.cs new file mode 100644 index 00000000..f460e6dc --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ChildClass.cs @@ -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 ChildClass : BaseClass + { + public new bool IsTransient { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ChildClassVirtual.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ChildClassVirtual.cs new file mode 100644 index 00000000..6d51dbfe --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ChildClassVirtual.cs @@ -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 ChildClassVirtual : BaseClassVirtual + { + public new virtual bool IsTransient { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ChildDataContractWithHidden.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ChildDataContractWithHidden.cs new file mode 100644 index 00000000..a7ebacec --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ChildDataContractWithHidden.cs @@ -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 + +#if !NET20 +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ChildDataContractWithHidden : BaseDataContractWithHidden + { + [DataMember(Name = "NewMember")] + public new virtual string NewMember { get; set; } + + public override string VirtualMember { get; set; } + public string AddedMember { get; set; } + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithImplicitOperator.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithImplicitOperator.cs new file mode 100644 index 00000000..f9c05778 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithImplicitOperator.cs @@ -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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ClassWithImplicitOperator + { + public string Value { get; set; } + + public static implicit operator ClassWithImplicitOperator(string value) + { + return new ClassWithImplicitOperator() { Value = value }; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithTimeSpan.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithTimeSpan.cs new file mode 100644 index 00000000..73a43874 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithTimeSpan.cs @@ -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 + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ClassWithTimeSpan + { + public TimeSpan TimeSpanField; + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CommentTestObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CommentTestObject.cs new file mode 100644 index 00000000..b3783fc0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CommentTestObject.cs @@ -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 CommentTestObject + { + public bool? A { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorAndDefaultValueAttributeTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorAndDefaultValueAttributeTestClass.cs new file mode 100644 index 00000000..12fa37b6 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorAndDefaultValueAttributeTestClass.cs @@ -0,0 +1,42 @@ +#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.ComponentModel; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public sealed class ConstructorAndDefaultValueAttributeTestClass + { + public ConstructorAndDefaultValueAttributeTestClass(string testProperty1) + { + TestProperty1 = testProperty1; + } + + public string TestProperty1 { get; set; } + + [DefaultValue(21)] + public int TestProperty2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorAndRequiredTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorAndRequiredTestClass.cs new file mode 100644 index 00000000..5ffeb449 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorAndRequiredTestClass.cs @@ -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 sealed class ConstructorAndRequiredTestClass + { + public ConstructorAndRequiredTestClass(string testProperty1) + { + TestProperty1 = testProperty1; + } + + public string TestProperty1 { get; set; } + + [JsonProperty(Required = Required.AllowNull)] + public int TestProperty2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DataContractPrivateMembers.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DataContractPrivateMembers.cs new file mode 100644 index 00000000..5c21859b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DataContractPrivateMembers.cs @@ -0,0 +1,67 @@ +#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 + +#if !NET20 +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [DataContract] + public class DataContractPrivateMembers + { + public DataContractPrivateMembers() + { + } + + public DataContractPrivateMembers(string name, int age, int rank, string title) + { + _name = name; + Age = age; + Rank = rank; + Title = title; + } + + [DataMember] + private string _name; + + [DataMember(Name = "_age")] + private int Age { get; set; } + + [JsonProperty] + private int Rank { get; set; } + + [JsonProperty(PropertyName = "JsonTitle")] + [DataMember(Name = "DataTitle")] + private string Title { get; set; } + + public string NotIncluded { get; set; } + + public override string ToString() + { + return "_name: " + _name + ", _age: " + Age + ", Rank: " + Rank + ", JsonTitle: " + Title; + } + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKeyCast.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKeyCast.cs new file mode 100644 index 00000000..c39404d5 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKeyCast.cs @@ -0,0 +1,52 @@ +#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 +{ + internal class DictionaryKeyCast + { + private String _name; + private int _number; + + public DictionaryKeyCast(String name, int number) + { + _name = name; + _number = number; + } + + public override string ToString() + { + return _name + " " + _number; + } + + public static implicit operator DictionaryKeyCast(string dictionaryKey) + { + var strings = dictionaryKey.Split(' '); + return new DictionaryKeyCast(strings[0], Convert.ToInt32(strings[1])); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKeyContractResolver.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKeyContractResolver.cs new file mode 100644 index 00000000..0cec51b0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKeyContractResolver.cs @@ -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 + +using System.Globalization; +using Newtonsoft.Json.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DictionaryKeyContractResolver : DefaultContractResolver + { + protected override string ResolveDictionaryKey(string dictionaryKey) + { + return dictionaryKey; + } + + protected override string ResolvePropertyName(string propertyName) + { +#if DNXCORE50 + return propertyName.ToUpperInvariant(); +#else + return propertyName.ToUpper(CultureInfo.InvariantCulture); +#endif + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryWithNoDefaultConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryWithNoDefaultConstructor.cs new file mode 100644 index 00000000..90ae99cc --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryWithNoDefaultConstructor.cs @@ -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.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DictionaryWithNoDefaultConstructor : Dictionary + { + public DictionaryWithNoDefaultConstructor(IEnumerable> initial) + { + foreach (KeyValuePair pair in initial) + { + Add(pair.Key, pair.Value); + } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryWithNoNull.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryWithNoNull.cs new file mode 100644 index 00000000..54a174bb --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryWithNoNull.cs @@ -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 +{ + [JsonObject(ItemRequired = Required.DisallowNull)] + public class DictionaryWithNoNull + { + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/EnumA.cs b/Src/Newtonsoft.Json.Tests/TestObjects/EnumA.cs new file mode 100644 index 00000000..97494465 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/EnumA.cs @@ -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 + +#if !NET20 +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public enum EnumA + { + [EnumMember(Value = "value_a")] + ValueA + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ErroringClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ErroringClass.cs new file mode 100644 index 00000000..80a41ff1 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ErroringClass.cs @@ -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 + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ErroringClass + { + public DateTime Tags { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ExistingValueClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ExistingValueClass.cs new file mode 100644 index 00000000..d8a15b85 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ExistingValueClass.cs @@ -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 + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ExistingValueClass + { + public Dictionary Dictionary { get; set; } + public List List { get; set; } + + public ExistingValueClass() + { + Dictionary = new Dictionary + { + { "existing", "yup" } + }; + List = new List + { + "existing" + }; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Foo1.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Foo1.cs new file mode 100644 index 00000000..6082b3ce --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Foo1.cs @@ -0,0 +1,64 @@ +#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 + +#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 Foo1 + { + public object foo { get; set; } + } + + public class Foo1 : Foo1 + { + public new T foo { get; set; } + + public T foo2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Foo64.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Foo64.cs new file mode 100644 index 00000000..d18331ea --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Foo64.cs @@ -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 Foo64 + { + public string Blah { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/FooBar1.cs b/Src/Newtonsoft.Json.Tests/TestObjects/FooBar1.cs new file mode 100644 index 00000000..33f5d371 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/FooBar1.cs @@ -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 FooBar1 : Foo1 + { + public new Bar1 foo { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/FooRequired.cs b/Src/Newtonsoft.Json.Tests/TestObjects/FooRequired.cs new file mode 100644 index 00000000..57b2f074 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/FooRequired.cs @@ -0,0 +1,44 @@ +#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 FooRequired + { + [JsonProperty(Required = Required.Always)] + public List Bars { get; private set; } + + public FooRequired(IEnumerable bars) + { + Bars = new List(); + if (bars != null) + { + Bars.AddRange(bars); + } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/GenericIEnumerableWithImplicitConversion.cs b/Src/Newtonsoft.Json.Tests/TestObjects/GenericIEnumerableWithImplicitConversion.cs new file mode 100644 index 00000000..556b340b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/GenericIEnumerableWithImplicitConversion.cs @@ -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 + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class GenericIEnumerableWithImplicitConversion + { + public IEnumerable Enumerable { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IKeyValueId.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IKeyValueId.cs new file mode 100644 index 00000000..53b4bc46 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IKeyValueId.cs @@ -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 interface IKeyValueId + { + int Id { get; set; } + string Key { get; set; } + string Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IMainClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IMainClass.cs new file mode 100644 index 00000000..44d259ec --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IMainClass.cs @@ -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 interface IMainClass + { + int ID { get; set; } + string Name { get; set; } + ISubclass Subclass { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ISubclass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ISubclass.cs new file mode 100644 index 00000000..e8a85628 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ISubclass.cs @@ -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 interface ISubclass : ISubclassBase + { + new bool P1 { get; set; } + int P2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ISubclassBase.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ISubclassBase.cs new file mode 100644 index 00000000..a213d0fa --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ISubclassBase.cs @@ -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 interface ISubclassBase + { + int ID { get; set; } + string Name { get; set; } + bool P1 { get; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredPropertiesContractResolver.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredPropertiesContractResolver.cs new file mode 100644 index 00000000..966e70fc --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredPropertiesContractResolver.cs @@ -0,0 +1,43 @@ +#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 Newtonsoft.Json.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class IgnoredPropertiesContractResolver : DefaultContractResolver + { + public override JsonContract ResolveContract(Type type) + { + if (type == typeof(Version)) + { + throw new Exception("Error!"); + } + + return base.ResolveContract(type); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredPropertiesTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredPropertiesTestClass.cs new file mode 100644 index 00000000..feb82bfd --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredPropertiesTestClass.cs @@ -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; +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class IgnoredPropertiesTestClass + { + [JsonIgnore] + public Version IgnoredProperty { get; set; } + + [JsonIgnore] + public List IgnoredList { get; set; } + + [JsonIgnore] + public Dictionary IgnoredDictionary { get; set; } + + [JsonProperty(Required = Required.Always)] + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredProperty.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredProperty.cs new file mode 100644 index 00000000..87d0cfc5 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoredProperty.cs @@ -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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class IgnoredProperty + { + [JsonIgnore] + [JsonProperty(Required = Required.Always)] + public string StringProp1 { get; set; } + + [JsonIgnore] + public string StringProp2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ImmutableStruct.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ImmutableStruct.cs new file mode 100644 index 00000000..81f8f5a2 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ImmutableStruct.cs @@ -0,0 +1,39 @@ +#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 struct ImmutableStruct + { + public ImmutableStruct(string value) + { + Value = value; + Value2 = 0; + } + + public string Value { get; } + public int Value2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IncompleteTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IncompleteTestClass.cs new file mode 100644 index 00000000..89560d6a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IncompleteTestClass.cs @@ -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 IncompleteTestClass + { + public int Key { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/JRawValueTestObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/JRawValueTestObject.cs new file mode 100644 index 00000000..32ff7034 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/JRawValueTestObject.cs @@ -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 + +using Newtonsoft.Json.Linq; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class JRawValueTestObject + { + public JRaw Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/KeyValueId.cs b/Src/Newtonsoft.Json.Tests/TestObjects/KeyValueId.cs new file mode 100644 index 00000000..12f2222b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/KeyValueId.cs @@ -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 KeyValueId : IKeyValueId + { + public int Id { get; set; } + public string Key { get; set; } + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Link.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Link.cs new file mode 100644 index 00000000..9dd875a9 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Link.cs @@ -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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class Link + { + /// + /// The unique identifier. + /// + public int Id; + + /// + /// The parent information identifier. + /// + public int ParentId; + + /// + /// The child information identifier. + /// + public int ChildId; + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ListSourceTest.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ListSourceTest.cs new file mode 100644 index 00000000..548f4612 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ListSourceTest.cs @@ -0,0 +1,53 @@ +#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; +using System.ComponentModel; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ListSourceTest : IListSource + { + private string str; + + public string strprop + { + get { return str; } + set { str = value; } + } + + [JsonIgnore] + public bool ContainsListCollection + { + get { return false; } + } + + public IList GetList() + { + return new List(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MainClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MainClass.cs new file mode 100644 index 00000000..08d968a5 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MainClass.cs @@ -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 MainClass : IMainClass + { + public int ID { get; set; } + public string Name { get; set; } + public ISubclass Subclass { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MyFactory.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MyFactory.cs new file mode 100644 index 00000000..fda5c63d --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MyFactory.cs @@ -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 MyFactory + { + public static ISubclass InstantiateSubclass() + { + return new Subclass + { + ID = 123, + Name = "ABC", + P1 = true, + P2 = 44 + }; + } + + public static IMainClass InstantiateManiClass() + { + return new MainClass + { + ID = 567, + Name = "XYZ", + Subclass = InstantiateSubclass() + }; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NullTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NullTestClass.cs new file mode 100644 index 00000000..4fb29016 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NullTestClass.cs @@ -0,0 +1,38 @@ +#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 Newtonsoft.Json.Linq; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class NullTestClass + { + public JObject Value1 { get; set; } + public JValue Value2 { get; set; } + public JRaw Value3 { get; set; } + public JToken Value4 { get; set; } + public object Value5 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PreserveReferencesCallbackTestObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PreserveReferencesCallbackTestObject.cs new file mode 100644 index 00000000..2737f511 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PreserveReferencesCallbackTestObject.cs @@ -0,0 +1,85 @@ +#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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(PORTABLE || PORTABLE40 || DNXCORE50) + public class PreserveReferencesCallbackTestObject : ISerializable + { + internal string _stringValue; + internal int _intValue; + internal PersonReference _person1; + internal PersonReference _person2; + internal PersonReference _person3; + internal PreserveReferencesCallbackTestObject _parent; + internal SerializationInfo _serializationInfo; + + public PreserveReferencesCallbackTestObject(string stringValue, int intValue, PersonReference p1, PersonReference p2, PersonReference p3) + { + _stringValue = stringValue; + _intValue = intValue; + _person1 = p1; + _person2 = p2; + _person3 = p3; + } + + protected PreserveReferencesCallbackTestObject(SerializationInfo info, StreamingContext context) + { + _serializationInfo = info; + } + + public void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("stringValue", _stringValue); + info.AddValue("intValue", _intValue); + info.AddValue("person1", _person1, typeof(PersonReference)); + info.AddValue("person2", _person2, typeof(PersonReference)); + info.AddValue("person3", _person3, typeof(PersonReference)); + info.AddValue("parent", _parent, typeof(PreserveReferencesCallbackTestObject)); + } + + [OnDeserialized] + private void OnDeserializedMethod(StreamingContext context) + { + if (_serializationInfo == null) + { + return; + } + + _stringValue = _serializationInfo.GetString("stringValue"); + _intValue = _serializationInfo.GetInt32("intValue"); + _person1 = (PersonReference)_serializationInfo.GetValue("person1", typeof(PersonReference)); + _person2 = (PersonReference)_serializationInfo.GetValue("person2", typeof(PersonReference)); + _person3 = (PersonReference)_serializationInfo.GetValue("person3", typeof(PersonReference)); + _parent = (PreserveReferencesCallbackTestObject)_serializationInfo.GetValue("parent", typeof(PreserveReferencesCallbackTestObject)); + + _serializationInfo = null; + } + } +#endif + +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/RequiredPropertyConstructorTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/RequiredPropertyConstructorTestClass.cs new file mode 100644 index 00000000..c9e8b55b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/RequiredPropertyConstructorTestClass.cs @@ -0,0 +1,38 @@ +#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 RequiredPropertyConstructorTestClass + { + public RequiredPropertyConstructorTestClass(string name) + { + Name = name; + } + + [JsonRequired] + internal string Name { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/RequiredPropertyTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/RequiredPropertyTestClass.cs new file mode 100644 index 00000000..5c179b04 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/RequiredPropertyTestClass.cs @@ -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 RequiredPropertyTestClass + { + [JsonRequired] + internal string Name { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericProperty.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericProperty.cs new file mode 100644 index 00000000..d8aaf64e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericProperty.cs @@ -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 ResponseWithNewGenericProperty : SimpleResponse + { + public new T Data { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericPropertyOverride.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericPropertyOverride.cs new file mode 100644 index 00000000..5730296f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericPropertyOverride.cs @@ -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 ResponseWithNewGenericPropertyOverride : ResponseWithNewGenericPropertyVirtual + { + public override T Data { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericPropertyVirtual.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericPropertyVirtual.cs new file mode 100644 index 00000000..fef49b45 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ResponseWithNewGenericPropertyVirtual.cs @@ -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 ResponseWithNewGenericPropertyVirtual : SimpleResponse + { + public new virtual T Data { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/SimpleResponse.cs b/Src/Newtonsoft.Json.Tests/TestObjects/SimpleResponse.cs new file mode 100644 index 00000000..5a4090e9 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/SimpleResponse.cs @@ -0,0 +1,43 @@ +#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 abstract class SimpleResponse + { + public string Result { get; set; } + public string Message { get; set; } + public object Data { get; set; } + + protected SimpleResponse() + { + } + + protected SimpleResponse(string message) + { + Message = message; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/SubWithContractNewProperties.cs b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithContractNewProperties.cs new file mode 100644 index 00000000..8e97a3b9 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithContractNewProperties.cs @@ -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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + [DataContract] + public class SubWithContractNewProperties : BaseWithContract + { +#pragma warning disable 108, 114 + [DataMember(Name = "VirtualWithDataMemberSub")] + public string VirtualWithDataMember { get; set; } + + [DataMember(Name = "Virtual2")] + public string Virtual { get; set; } + + [DataMember(Name = "WithDataMemberSub")] + public string WithDataMember { get; set; } + + [DataMember(Name = "JustAProperty2")] + public string JustAProperty { get; set; } +#pragma warning restore 108, 114 + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/SubWithContractVirtualProperties.cs b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithContractVirtualProperties.cs new file mode 100644 index 00000000..70b1fc4e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithContractVirtualProperties.cs @@ -0,0 +1,38 @@ +#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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + [DataContract] + public class SubWithContractVirtualProperties : BaseWithContract + { + [DataMember(Name = "VirtualWithDataMemberSub")] + public virtual string VirtualWithDataMember { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/SubWithoutContractNewProperties.cs b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithoutContractNewProperties.cs new file mode 100644 index 00000000..8aacf00b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithoutContractNewProperties.cs @@ -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 + +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + [DataContract] + public class SubWithoutContractNewProperties : BaseWithContract + { +#pragma warning disable 108, 114 + [DataMember(Name = "VirtualWithDataMemberSub")] + public string VirtualWithDataMember { get; set; } + + public string Virtual { get; set; } + + [DataMember(Name = "WithDataMemberSub")] + public string WithDataMember { get; set; } + + public string JustAProperty { get; set; } +#pragma warning restore 108, 114 + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/SubWithoutContractVirtualProperties.cs b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithoutContractVirtualProperties.cs new file mode 100644 index 00000000..c728a375 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/SubWithoutContractVirtualProperties.cs @@ -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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + [DataContract] + public class SubWithoutContractVirtualProperties : BaseWithContract + { + public override string VirtualWithDataMember { get; set; } + + [DataMember(Name = "VirtualSub")] + public override string Virtual { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Subclass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Subclass.cs new file mode 100644 index 00000000..f9e2a396 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Subclass.cs @@ -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 Subclass : ISubclass + { + public int ID { get; set; } + public string Name { get; set; } + public bool P1 { get; set; } + public int P2 { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ThisGenericTest.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ThisGenericTest.cs new file mode 100644 index 00000000..0c650c23 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ThisGenericTest.cs @@ -0,0 +1,83 @@ +#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 System.Linq; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ThisGenericTest where T : IKeyValueId + { + private Dictionary _dict1 = new Dictionary(); + + public string MyProperty { get; set; } + + public void Add(T item) + { + _dict1.Add(item.Key, item); + } + + public T this[string key] + { + get { return _dict1[key]; } + set { _dict1[key] = value; } + } + + public T this[int id] + { + get { return Enumerable.FirstOrDefault(_dict1.Values, x => x.Id == id); } + set + { + var item = this[id]; + + if (item == null) + { + Add(value); + } + else + { + _dict1[item.Key] = value; + } + } + } + + public string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + public T[] TheItems + { + get { return Enumerable.ToArray(_dict1.Values); } + set + { + foreach (var item in value) + { + Add(item); + } + } + } + } +} \ No newline at end of file