-Code reformat

This commit is contained in:
James Newton-King
2013-10-20 15:08:39 +13:00
parent d03963016e
commit bcd6982419
466 changed files with 71645 additions and 71598 deletions
@@ -44,120 +44,114 @@ using Newtonsoft.Json.Serialization;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class WebApiIntegrationTests : TestFixtureBase
{
[Test]
public void SerializeSerializableType()
[TestFixture]
public class WebApiIntegrationTests : TestFixtureBase
{
SerializableType serializableType = new SerializableType("protected")
[Test]
public void SerializeSerializableType()
{
publicField = "public",
protectedInternalField = "protected internal",
internalField = "internal",
PublicProperty = "private",
nonSerializedField = "Error"
};
SerializableType serializableType = new SerializableType("protected")
{
publicField = "public",
protectedInternalField = "protected internal",
internalField = "internal",
PublicProperty = "private",
nonSerializedField = "Error"
};
#if !(SILVERLIGHT || NETFX_CORE || NET20 || PORTABLE || PORTABLE40)
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(SerializableType));
dataContractJsonSerializer.WriteObject(ms, serializableType);
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(SerializableType));
dataContractJsonSerializer.WriteObject(ms, serializableType);
string dtJson = Encoding.UTF8.GetString(ms.ToArray());
string dtExpected = @"{""internalField"":""internal"",""privateField"":""private"",""protectedField"":""protected"",""protectedInternalField"":""protected internal"",""publicField"":""public""}";
string dtJson = Encoding.UTF8.GetString(ms.ToArray());
string dtExpected = @"{""internalField"":""internal"",""privateField"":""private"",""protectedField"":""protected"",""protectedInternalField"":""protected internal"",""publicField"":""public""}";
Assert.AreEqual(dtExpected, dtJson);
Assert.AreEqual(dtExpected, dtJson);
#endif
string expected = "{\"publicField\":\"public\",\"internalField\":\"internal\",\"protectedInternalField\":\"protected internal\",\"protectedField\":\"protected\",\"privateField\":\"private\"}";
string json = JsonConvert.SerializeObject(serializableType, new JsonSerializerSettings
string expected = "{\"publicField\":\"public\",\"internalField\":\"internal\",\"protectedInternalField\":\"protected internal\",\"protectedField\":\"protected\",\"privateField\":\"private\"}";
string json = JsonConvert.SerializeObject(serializableType, new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = false
#endif
}
});
Assert.AreEqual(expected, json);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeInheritedType()
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = false
InheritedType serializableType = new InheritedType("protected")
{
publicField = "public",
protectedInternalField = "protected internal",
internalField = "internal",
PublicProperty = "private",
nonSerializedField = "Error",
inheritedTypeField = "inherited"
};
string json = JsonConvert.SerializeObject(serializableType);
Assert.AreEqual(@"{""inheritedTypeField"":""inherited"",""publicField"":""public"",""PublicProperty"":""private""}", json);
}
#endif
}
});
}
Assert.AreEqual(expected, json);
public class InheritedType : SerializableType
{
public string inheritedTypeField;
public InheritedType(string protectedFieldValue) : base(protectedFieldValue)
{
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeInheritedType()
{
InheritedType serializableType = new InheritedType("protected")
{
publicField = "public",
protectedInternalField = "protected internal",
internalField = "internal",
PublicProperty = "private",
nonSerializedField = "Error",
inheritedTypeField = "inherited"
};
string json = JsonConvert.SerializeObject(serializableType);
Assert.AreEqual(@"{""inheritedTypeField"":""inherited"",""publicField"":""public"",""PublicProperty"":""private""}", json);
}
#endif
}
public class InheritedType : SerializableType
{
public string inheritedTypeField;
public InheritedType(string protectedFieldValue) : base(protectedFieldValue)
{
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Serializable]
[Serializable]
#else
[JsonObject(MemberSerialization.Fields)]
[JsonObject(MemberSerialization.Fields)]
#endif
public class SerializableType : IEquatable<SerializableType>
{
public SerializableType(string protectedFieldValue)
public class SerializableType : IEquatable<SerializableType>
{
this.protectedField = protectedFieldValue;
}
public SerializableType(string protectedFieldValue)
{
protectedField = protectedFieldValue;
}
public string publicField;
internal string internalField;
protected internal string protectedInternalField;
protected string protectedField;
private string privateField;
public string publicField;
internal string internalField;
protected internal string protectedInternalField;
protected string protectedField;
private string privateField;
public string PublicProperty
{
get
{
return privateField;
}
set
{
this.privateField = value;
}
}
public string PublicProperty
{
get { return privateField; }
set { privateField = value; }
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[NonSerialized]
[NonSerialized]
#else
[JsonIgnore]
[JsonIgnore]
#endif
public string nonSerializedField;
public string nonSerializedField;
public bool Equals(SerializableType other)
{
return this.publicField == other.publicField &&
this.internalField == other.internalField &&
this.protectedInternalField == other.protectedInternalField &&
this.protectedField == other.protectedField &&
this.privateField == other.privateField;
public bool Equals(SerializableType other)
{
return publicField == other.publicField &&
internalField == other.internalField &&
protectedInternalField == other.protectedInternalField &&
protectedField == other.protectedField &&
privateField == other.privateField;
}
}
}
}