-More object creation refactoring

This commit is contained in:
James Newton-King
2014-05-07 15:24:42 +12:00
parent 3e4eb24047
commit cf939ffc29
10 changed files with 317 additions and 162 deletions
@@ -4952,27 +4952,6 @@ To fix this error either change the environment to be fully trusted, change the
Assert.IsTrue(deserializedResponse.Data.DeepEquals(response.Data));
}
public abstract class Test<T>
{
public abstract T Value { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class DecimalTest : Test<decimal>
{
protected DecimalTest()
{
}
public DecimalTest(decimal val)
{
Value = val;
}
[JsonProperty]
public override decimal Value { get; set; }
}
[Test]
public void DeserializeMinValueDecimal()
{
@@ -4983,24 +4962,6 @@ To fix this error either change the environment to be fully trusted, change the
Assert.AreEqual(decimal.MinValue, obj.Value);
}
public class NonPublicConstructorWithJsonConstructor
{
public string Value { get; private set; }
public string Constructor { get; private set; }
[JsonConstructor]
private NonPublicConstructorWithJsonConstructor()
{
Constructor = "NonPublic";
}
public NonPublicConstructorWithJsonConstructor(string value)
{
Value = value;
Constructor = "Public Paramatized";
}
}
[Test]
public void NonPublicConstructorWithJsonConstructorTest()
{
@@ -5008,24 +4969,6 @@ To fix this error either change the environment to be fully trusted, change the
Assert.AreEqual("NonPublic", c.Constructor);
}
public class PublicConstructorOverridenByJsonConstructor
{
public string Value { get; private set; }
public string Constructor { get; private set; }
public PublicConstructorOverridenByJsonConstructor()
{
Constructor = "NonPublic";
}
[JsonConstructor]
public PublicConstructorOverridenByJsonConstructor(string value)
{
Value = value;
Constructor = "Public Paramatized";
}
}
[Test]
public void PublicConstructorOverridenByJsonConstructorTest()
{
@@ -5034,27 +4977,6 @@ To fix this error either change the environment to be fully trusted, change the
Assert.AreEqual("value!", c.Value);
}
public class MultipleParamatrizedConstructorsJsonConstructor
{
public string Value { get; private set; }
public int Age { get; private set; }
public string Constructor { get; private set; }
public MultipleParamatrizedConstructorsJsonConstructor(string value)
{
Value = value;
Constructor = "Public Paramatized 1";
}
[JsonConstructor]
public MultipleParamatrizedConstructorsJsonConstructor(string value, int age)
{
Value = value;
Age = age;
Constructor = "Public Paramatized 2";
}
}
[Test]
public void MultipleParamatrizedConstructorsJsonConstructorTest()
{
@@ -5064,11 +4986,6 @@ To fix this error either change the environment to be fully trusted, change the
Assert.AreEqual(1, c.Age);
}
public class EnumerableClass
{
public IEnumerable<string> Enumerable { get; set; }
}
[Test]
public void DeserializeEnumerable()
{
@@ -5094,18 +5011,6 @@ To fix this error either change the environment to be fully trusted, change the
Assert.AreEqual("Three", c2.Enumerable.ElementAt(2));
}
[JsonObject(MemberSerialization.OptIn)]
public class ItemBase
{
[JsonProperty]
public string Name { get; set; }
}
public class ComplexItem : ItemBase
{
public Stream Source { get; set; }
}
[Test]
public void SerializeAttributesOnBase()
{
@@ -5118,14 +5023,6 @@ To fix this error either change the environment to be fully trusted, change the
}", json);
}
public class DeserializeStringConvert
{
public string Name { get; set; }
public int Age { get; set; }
public double Height { get; set; }
public decimal Price { get; set; }
}
[Test]
public void DeserializeStringEnglish()
{
@@ -7961,4 +7858,107 @@ Parameter name: value",
}
#endif
}
public abstract class Test<T>
{
public abstract T Value { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class DecimalTest : Test<decimal>
{
protected DecimalTest()
{
}
public DecimalTest(decimal val)
{
Value = val;
}
[JsonProperty]
public override decimal Value { get; set; }
}
public class NonPublicConstructorWithJsonConstructor
{
public string Value { get; private set; }
public string Constructor { get; private set; }
[JsonConstructor]
private NonPublicConstructorWithJsonConstructor()
{
Constructor = "NonPublic";
}
public NonPublicConstructorWithJsonConstructor(string value)
{
Value = value;
Constructor = "Public Paramatized";
}
}
public class PublicConstructorOverridenByJsonConstructor
{
public string Value { get; private set; }
public string Constructor { get; private set; }
public PublicConstructorOverridenByJsonConstructor()
{
Constructor = "NonPublic";
}
[JsonConstructor]
public PublicConstructorOverridenByJsonConstructor(string value)
{
Value = value;
Constructor = "Public Paramatized";
}
}
public class MultipleParamatrizedConstructorsJsonConstructor
{
public string Value { get; private set; }
public int Age { get; private set; }
public string Constructor { get; private set; }
public MultipleParamatrizedConstructorsJsonConstructor(string value)
{
Value = value;
Constructor = "Public Paramatized 1";
}
[JsonConstructor]
public MultipleParamatrizedConstructorsJsonConstructor(string value, int age)
{
Value = value;
Age = age;
Constructor = "Public Paramatized 2";
}
}
public class EnumerableClass
{
public IEnumerable<string> Enumerable { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class ItemBase
{
[JsonProperty]
public string Name { get; set; }
}
public class ComplexItem : ItemBase
{
public Stream Source { get; set; }
}
public class DeserializeStringConvert
{
public string Name { get; set; }
public int Age { get; set; }
public double Height { get; set; }
public decimal Price { get; set; }
}
}