-Changed netstandard1.1 to netstandard1.3
-Added support for ISerializable interface to netstandard1.3+ -Added support for SerializableAttribute and NonSerializedAttribute to netstandard1.3+
This commit is contained in:
@@ -4158,7 +4158,7 @@ Path '', line 1, position 1.");
|
||||
{
|
||||
ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
IgnoreSerializableAttribute = true
|
||||
#endif
|
||||
}
|
||||
@@ -4175,7 +4175,7 @@ Path '', line 1, position 1.");
|
||||
{
|
||||
ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
IgnoreSerializableAttribute = true
|
||||
#endif
|
||||
}
|
||||
@@ -4192,7 +4192,7 @@ Path '', line 1, position 1.");
|
||||
{
|
||||
ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
IgnoreSerializableAttribute = true
|
||||
#endif
|
||||
}
|
||||
@@ -4984,84 +4984,7 @@ Path '', line 1, position 1.");
|
||||
Assert.AreEqual("value", newModelStateDictionary["key"]);
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
public class ISerializableTestObject : ISerializable
|
||||
{
|
||||
internal string _stringValue;
|
||||
internal int _intValue;
|
||||
internal DateTimeOffset _dateTimeOffsetValue;
|
||||
internal Person _personValue;
|
||||
internal Person _nullPersonValue;
|
||||
internal int? _nullableInt;
|
||||
internal bool _booleanValue;
|
||||
internal byte _byteValue;
|
||||
internal char _charValue;
|
||||
internal DateTime _dateTimeValue;
|
||||
internal decimal _decimalValue;
|
||||
internal short _shortValue;
|
||||
internal long _longValue;
|
||||
internal sbyte _sbyteValue;
|
||||
internal float _floatValue;
|
||||
internal ushort _ushortValue;
|
||||
internal uint _uintValue;
|
||||
internal ulong _ulongValue;
|
||||
|
||||
public ISerializableTestObject(string stringValue, int intValue, DateTimeOffset dateTimeOffset, Person personValue)
|
||||
{
|
||||
_stringValue = stringValue;
|
||||
_intValue = intValue;
|
||||
_dateTimeOffsetValue = dateTimeOffset;
|
||||
_personValue = personValue;
|
||||
_dateTimeValue = new DateTime(0, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
protected ISerializableTestObject(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
_stringValue = info.GetString("stringValue");
|
||||
_intValue = info.GetInt32("intValue");
|
||||
_dateTimeOffsetValue = (DateTimeOffset)info.GetValue("dateTimeOffsetValue", typeof(DateTimeOffset));
|
||||
_personValue = (Person)info.GetValue("personValue", typeof(Person));
|
||||
_nullPersonValue = (Person)info.GetValue("nullPersonValue", typeof(Person));
|
||||
_nullableInt = (int?)info.GetValue("nullableInt", typeof(int?));
|
||||
|
||||
_booleanValue = info.GetBoolean("booleanValue");
|
||||
_byteValue = info.GetByte("byteValue");
|
||||
_charValue = info.GetChar("charValue");
|
||||
_dateTimeValue = info.GetDateTime("dateTimeValue");
|
||||
_decimalValue = info.GetDecimal("decimalValue");
|
||||
_shortValue = info.GetInt16("shortValue");
|
||||
_longValue = info.GetInt64("longValue");
|
||||
_sbyteValue = info.GetSByte("sbyteValue");
|
||||
_floatValue = info.GetSingle("floatValue");
|
||||
_ushortValue = info.GetUInt16("ushortValue");
|
||||
_uintValue = info.GetUInt32("uintValue");
|
||||
_ulongValue = info.GetUInt64("ulongValue");
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("stringValue", _stringValue);
|
||||
info.AddValue("intValue", _intValue);
|
||||
info.AddValue("dateTimeOffsetValue", _dateTimeOffsetValue);
|
||||
info.AddValue("personValue", _personValue);
|
||||
info.AddValue("nullPersonValue", _nullPersonValue);
|
||||
info.AddValue("nullableInt", null);
|
||||
|
||||
info.AddValue("booleanValue", _booleanValue);
|
||||
info.AddValue("byteValue", _byteValue);
|
||||
info.AddValue("charValue", _charValue);
|
||||
info.AddValue("dateTimeValue", _dateTimeValue);
|
||||
info.AddValue("decimalValue", _decimalValue);
|
||||
info.AddValue("shortValue", _shortValue);
|
||||
info.AddValue("longValue", _longValue);
|
||||
info.AddValue("sbyteValue", _sbyteValue);
|
||||
info.AddValue("floatValue", _floatValue);
|
||||
info.AddValue("ushortValue", _ushortValue);
|
||||
info.AddValue("uintValue", _uintValue);
|
||||
info.AddValue("ulongValue", _ulongValue);
|
||||
}
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
#if DEBUG
|
||||
[Test]
|
||||
public void SerializeISerializableInPartialTrustWithIgnoreInterface()
|
||||
@@ -5094,7 +5017,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(true);
|
||||
JsonTypeReflector.SetFullyTrusted(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5114,7 +5037,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(true);
|
||||
JsonTypeReflector.SetFullyTrusted(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5135,7 +5058,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
JsonTypeReflector.SetFullyTrusted(true);
|
||||
JsonTypeReflector.SetFullyTrusted(null);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -8091,24 +8014,19 @@ Path '', line 1, position 1.");
|
||||
Assert.AreEqual("", s);
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void SerializeAndDeserializeWithAttributes()
|
||||
{
|
||||
var testObj = new PersonSerializable() { Name = "John Doe", Age = 28 };
|
||||
var objDeserialized = SerializeAndDeserialize<PersonSerializable>(testObj);
|
||||
|
||||
var json = Serialize(testObj);
|
||||
var objDeserialized = Deserialize<PersonSerializable>(json);
|
||||
|
||||
Assert.AreEqual(testObj.Name, objDeserialized.Name);
|
||||
Assert.AreEqual(0, objDeserialized.Age);
|
||||
}
|
||||
|
||||
private T SerializeAndDeserialize<T>(T obj)
|
||||
where T : class
|
||||
{
|
||||
var json = Serialize(obj);
|
||||
return Deserialize<T>(json);
|
||||
}
|
||||
|
||||
private string Serialize<T>(T obj)
|
||||
where T : class
|
||||
{
|
||||
@@ -8622,15 +8540,18 @@ This is just junk, though.";
|
||||
public void SerializeTupleWithSerializableAttribute()
|
||||
{
|
||||
var tuple = Tuple.Create(500);
|
||||
|
||||
SerializableContractResolver contractResolver = new SerializableContractResolver();
|
||||
|
||||
var json = JsonConvert.SerializeObject(tuple, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new SerializableContractResolver()
|
||||
ContractResolver = contractResolver
|
||||
});
|
||||
Assert.AreEqual(@"{""m_Item1"":500}", json);
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<Tuple<int>>(json, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new SerializableContractResolver()
|
||||
ContractResolver = contractResolver
|
||||
});
|
||||
Assert.AreEqual(500, obj.Item1);
|
||||
}
|
||||
@@ -8891,7 +8812,7 @@ This is just junk, though.";
|
||||
|
||||
Assert.AreEqual(@"{""First"":""One"",""Second"":2}", json);
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
DefaultContractResolver r = new DefaultContractResolver();
|
||||
r.IgnoreSerializableAttribute = false;
|
||||
|
||||
@@ -9007,7 +8928,7 @@ This is just junk, though.";
|
||||
Assert.AreEqual(1234567890.123456m, d);
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void DontSerializeStaticFields()
|
||||
{
|
||||
@@ -10334,4 +10255,83 @@ This is just junk, though.";
|
||||
public string DataSource { get; }
|
||||
public string Project { get; }
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_1
|
||||
public class ISerializableTestObject : ISerializable
|
||||
{
|
||||
internal string _stringValue;
|
||||
internal int _intValue;
|
||||
internal DateTimeOffset _dateTimeOffsetValue;
|
||||
internal Person _personValue;
|
||||
internal Person _nullPersonValue;
|
||||
internal int? _nullableInt;
|
||||
internal bool _booleanValue;
|
||||
internal byte _byteValue;
|
||||
internal char _charValue;
|
||||
internal DateTime _dateTimeValue;
|
||||
internal decimal _decimalValue;
|
||||
internal short _shortValue;
|
||||
internal long _longValue;
|
||||
internal sbyte _sbyteValue;
|
||||
internal float _floatValue;
|
||||
internal ushort _ushortValue;
|
||||
internal uint _uintValue;
|
||||
internal ulong _ulongValue;
|
||||
|
||||
public ISerializableTestObject(string stringValue, int intValue, DateTimeOffset dateTimeOffset, Person personValue)
|
||||
{
|
||||
_stringValue = stringValue;
|
||||
_intValue = intValue;
|
||||
_dateTimeOffsetValue = dateTimeOffset;
|
||||
_personValue = personValue;
|
||||
_dateTimeValue = new DateTime(0, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
protected ISerializableTestObject(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
_stringValue = info.GetString("stringValue");
|
||||
_intValue = info.GetInt32("intValue");
|
||||
_dateTimeOffsetValue = (DateTimeOffset)info.GetValue("dateTimeOffsetValue", typeof(DateTimeOffset));
|
||||
_personValue = (Person)info.GetValue("personValue", typeof(Person));
|
||||
_nullPersonValue = (Person)info.GetValue("nullPersonValue", typeof(Person));
|
||||
_nullableInt = (int?)info.GetValue("nullableInt", typeof(int?));
|
||||
|
||||
_booleanValue = info.GetBoolean("booleanValue");
|
||||
_byteValue = info.GetByte("byteValue");
|
||||
_charValue = info.GetChar("charValue");
|
||||
_dateTimeValue = info.GetDateTime("dateTimeValue");
|
||||
_decimalValue = info.GetDecimal("decimalValue");
|
||||
_shortValue = info.GetInt16("shortValue");
|
||||
_longValue = info.GetInt64("longValue");
|
||||
_sbyteValue = info.GetSByte("sbyteValue");
|
||||
_floatValue = info.GetSingle("floatValue");
|
||||
_ushortValue = info.GetUInt16("ushortValue");
|
||||
_uintValue = info.GetUInt32("uintValue");
|
||||
_ulongValue = info.GetUInt64("ulongValue");
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("stringValue", _stringValue);
|
||||
info.AddValue("intValue", _intValue);
|
||||
info.AddValue("dateTimeOffsetValue", _dateTimeOffsetValue);
|
||||
info.AddValue("personValue", _personValue);
|
||||
info.AddValue("nullPersonValue", _nullPersonValue);
|
||||
info.AddValue("nullableInt", null);
|
||||
|
||||
info.AddValue("booleanValue", _booleanValue);
|
||||
info.AddValue("byteValue", _byteValue);
|
||||
info.AddValue("charValue", _charValue);
|
||||
info.AddValue("dateTimeValue", _dateTimeValue);
|
||||
info.AddValue("decimalValue", _decimalValue);
|
||||
info.AddValue("shortValue", _shortValue);
|
||||
info.AddValue("longValue", _longValue);
|
||||
info.AddValue("sbyteValue", _sbyteValue);
|
||||
info.AddValue("floatValue", _floatValue);
|
||||
info.AddValue("ushortValue", _ushortValue);
|
||||
info.AddValue("uintValue", _uintValue);
|
||||
info.AddValue("ulongValue", _ulongValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user