提交 7d22c02b 编写于 作者: S Shin Mao 提交者: GitHub

Support ISerializable in ReflectionOnly mode. (dotnet/corefx#14551)

* Support ISerializable in ReflectionOnly mode.

Fix dotnet/corefx#13071

* Address feedback.


Commit migrated from https://github.com/dotnet/corefx/commit/c573a141bbbd5d7027855890354668db99ae870c
上级 b05851d6
......@@ -21,7 +21,15 @@ public void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlOb
{
InvokeOnSerializing(obj, context, classContract);
obj = ResolveAdapterType(obj, classContract);
ReflectionWriteMembers(xmlWriter, obj, context, classContract, classContract, 0 /*childElementIndex*/, memberNames);
if (classContract.IsISerializable)
{
context.WriteISerializable(xmlWriter, (ISerializable) obj);
}
else
{
ReflectionWriteMembers(xmlWriter, obj, context, classContract, classContract, 0 /*childElementIndex*/, memberNames);
}
InvokeOnSerialized(obj, context, classContract);
}
......
......@@ -33,7 +33,15 @@ public object ReflectionReadClass(XmlReaderDelegator xmlReader, XmlObjectSeriali
context.AddNewObject(obj);
InvokeOnDeserializing(context, classContract, obj);
ReflectionReadMembers(xmlReader, context, memberNames, memberNamespaces, classContract, ref obj);
if (classContract.IsISerializable)
{
obj = ReadISerializable(xmlReader, context, classContract);
}
else
{
ReflectionReadMembers(xmlReader, context, memberNames, memberNamespaces, classContract, ref obj);
}
obj = ResolveAdapterObject(obj, classContract);
InvokeDeserializationCallback(obj);
InvokeOnDeserialized(context, classContract, obj);
......@@ -279,6 +287,16 @@ private object ReadItemOfPrimitiveType(XmlReaderDelegator xmlReader, XmlObjectSe
return value;
}
private static object ReadISerializable(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context, ClassDataContract classContract)
{
object obj;
SerializationInfo serializationInfo = context.ReadSerializationInfo(xmlReader, classContract.UnderlyingType);
StreamingContext streamingContext = context.GetStreamingContext();
ConstructorInfo iSerializableConstructor = classContract.GetISerializableConstructor();
obj = iSerializableConstructor.Invoke(new object[] { serializationInfo, streamingContext });
return obj;
}
// This method is a perf optimization for collections. The original method is ReflectionReadValue.
private CollectionReadItemDelegate GetReflectionReadValueDelegate(Type type)
{
......
......@@ -2240,9 +2240,6 @@ public static void DCJS_CreateJsonWriterTest()
}
}
#if ReflectionOnly
[ActiveIssue(13071)]
#endif
[Fact]
public static void DCJS_MyISerializableType()
{
......
......@@ -1431,9 +1431,6 @@ public static void DCS_RootNameNamespaceAndKnownTypesThroughConstructorAsXmlDict
Assert.StrictEqual(((SimpleKnownTypeValue)actual.SimpleTypeValue).StrProperty, "PropertyValue");
}
#if ReflectionOnly
[ActiveIssue(13071)]
#endif
[Fact]
public static void DCS_ExceptionObject()
{
......@@ -1448,9 +1445,6 @@ public static void DCS_ExceptionObject()
Assert.StrictEqual(value.HelpLink, actual.HelpLink);
}
#if ReflectionOnly
[ActiveIssue(13071)]
#endif
[Fact]
public static void DCS_ArgumentExceptionObject()
{
......@@ -1465,9 +1459,6 @@ public static void DCS_ArgumentExceptionObject()
Assert.StrictEqual(value.HelpLink, actual.HelpLink);
}
#if ReflectionOnly
[ActiveIssue(13071)]
#endif
[Fact]
public static void DCS_ExceptionMesageWithSpecialChars()
{
......@@ -1482,9 +1473,6 @@ public static void DCS_ExceptionMesageWithSpecialChars()
Assert.StrictEqual(value.HelpLink, actual.HelpLink);
}
#if ReflectionOnly
[ActiveIssue(13071)]
#endif
[Fact]
public static void DCS_InnerExceptionMesageWithSpecialChars()
{
......@@ -2756,9 +2744,6 @@ public static void XsdDataContractExporterTest()
Assert.Throws<PlatformNotSupportedException>(() => exporter.Export(typeof(Employee)));
}
#if ReflectionOnly
[ActiveIssue(13071)]
#endif
[Fact]
public static void DCS_MyISerializableType()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册