-Refactor tests

This commit is contained in:
James Newton-King
2017-07-23 17:58:21 +12:00
parent 36bcc55ee6
commit ebff7199e4
62 changed files with 2459 additions and 730 deletions
@@ -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<string>();
}
}
[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<ClassWithImplicitOperator> 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<Foo64>("{\"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<string> Bars { get; private set; }
public FooRequired(IEnumerable<string> bars)
{
Bars = new List<string>();
if (bars != null)
{
Bars.AddRange(bars);
}
}
}
[Test]
public void CoercedEmptyStringWithRequired()
{
@@ -523,16 +390,6 @@ namespace Newtonsoft.Json.Tests.Serialization
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<FooRequired>("{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<JsonSerializationException>(() => { 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<Version> IgnoredList { get; set; }
[JsonIgnore]
public Dictionary<string, Version> 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
{
/// <summary>
/// The unique identifier.
/// </summary>
public int Id;
/// <summary>
/// The parent information identifier.
/// </summary>
public int ParentId;
/// <summary>
/// The child information identifier.
/// </summary>
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<T> : SimpleResponse
{
public new T Data { get; set; }
}
public class ResponseWithNewGenericPropertyVirtual<T> : SimpleResponse
{
public new virtual T Data { get; set; }
}
public class ResponseWithNewGenericPropertyOverride<T> : ResponseWithNewGenericPropertyVirtual<T>
{
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<T> : 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<string, string> Dictionary { get; set; }
public List<string> List { get; set; }
public ExistingValueClass()
{
Dictionary = new Dictionary<string, string>
{
{ "existing", "yup" }
};
List = new List<string>
{
"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<T> where T : IKeyValueId
{
private Dictionary<string, T> _dict1 = new Dictionary<string, T>();
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<T>(); }
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<string, string>
{
public DictionaryWithNoDefaultConstructor(IEnumerable<KeyValuePair<string, string>> initial)
{
foreach (KeyValuePair<string, string> 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)
@@ -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<Foo1>(setFooJson);
var deserializedSetFoo = JsonConvert.DeserializeObject<Foo2>(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; }
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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
@@ -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
@@ -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
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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
@@ -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 };
}
}
}
@@ -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;
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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
@@ -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]));
}
}
}
@@ -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
}
}
}
@@ -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<string, string>
{
public DictionaryWithNoDefaultConstructor(IEnumerable<KeyValuePair<string, string>> initial)
{
foreach (KeyValuePair<string, string> pair in initial)
{
Add(pair.Key, pair.Value);
}
}
}
}
@@ -0,0 +1,33 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
[JsonObject(ItemRequired = Required.DisallowNull)]
public class DictionaryWithNoNull
{
public string Name { get; set; }
}
}
@@ -0,0 +1,37 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !NET20
using System.Runtime.Serialization;
namespace Newtonsoft.Json.Tests.TestObjects
{
public enum EnumA
{
[EnumMember(Value = "value_a")]
ValueA
}
}
#endif
@@ -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; }
}
}
@@ -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<string, string> Dictionary { get; set; }
public List<string> List { get; set; }
public ExistingValueClass()
{
Dictionary = new Dictionary<string, string>
{
{ "existing", "yup" }
};
List = new List<string>
{
"existing"
};
}
}
}
@@ -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<T> : Foo1
{
public new T foo { get; set; }
public T foo2 { get; set; }
}
}
@@ -0,0 +1,32 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public class Foo64
{
public string Blah { get; set; }
}
}
@@ -0,0 +1,32 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public class FooBar1 : Foo1
{
public new Bar1 foo { get; set; }
}
}
@@ -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<string> Bars { get; private set; }
public FooRequired(IEnumerable<string> bars)
{
Bars = new List<string>();
if (bars != null)
{
Bars.AddRange(bars);
}
}
}
}
@@ -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<ClassWithImplicitOperator> Enumerable { get; set; }
}
}
@@ -0,0 +1,34 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public interface IKeyValueId
{
int Id { get; set; }
string Key { get; set; }
string Value { get; set; }
}
}
@@ -0,0 +1,34 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public interface IMainClass
{
int ID { get; set; }
string Name { get; set; }
ISubclass Subclass { get; set; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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);
}
}
}
@@ -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<Version> IgnoredList { get; set; }
[JsonIgnore]
public Dictionary<string, Version> IgnoredDictionary { get; set; }
[JsonProperty(Required = Required.Always)]
public string Name { get; set; }
}
}
@@ -0,0 +1,37 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public class IgnoredProperty
{
[JsonIgnore]
[JsonProperty(Required = Required.Always)]
public string StringProp1 { get; set; }
[JsonIgnore]
public string StringProp2 { get; set; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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
{
/// <summary>
/// The unique identifier.
/// </summary>
public int Id;
/// <summary>
/// The parent information identifier.
/// </summary>
public int ParentId;
/// <summary>
/// The child information identifier.
/// </summary>
public int ChildId;
}
}
@@ -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<string>();
}
}
}
@@ -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; }
}
}
@@ -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()
};
}
}
}
@@ -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; }
}
}
@@ -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
}
@@ -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; }
}
}
@@ -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; }
}
}
@@ -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<T> : SimpleResponse
{
public new T Data { get; set; }
}
}
@@ -0,0 +1,32 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public class ResponseWithNewGenericPropertyOverride<T> : ResponseWithNewGenericPropertyVirtual<T>
{
public override T Data { get; set; }
}
}
@@ -0,0 +1,32 @@
#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
namespace Newtonsoft.Json.Tests.TestObjects
{
public class ResponseWithNewGenericPropertyVirtual<T> : SimpleResponse
{
public new virtual T Data { get; set; }
}
}
@@ -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;
}
}
}
@@ -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
}
@@ -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
}
@@ -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
}
@@ -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
}
@@ -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; }
}
}
@@ -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<T> where T : IKeyValueId
{
private Dictionary<string, T> _dict1 = new Dictionary<string, T>();
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<T>(_dict1.Values); }
set
{
foreach (var item in value)
{
Add(item);
}
}
}
}
}