From fc05116b03f08159732eb95a21eccc6486e944da Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 14 Apr 2015 22:00:33 +0900 Subject: [PATCH] [S.R.Serialization] implement XmlDataContract's interpreter method. --- .../XmlDataContract_static.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlDataContract_static.cs b/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlDataContract_static.cs index 6ff8070ca74..c8829ad53ff 100644 --- a/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlDataContract_static.cs +++ b/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlDataContract_static.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Xml; +using System.Xml.Serialization; namespace System.Runtime.Serialization { @@ -10,7 +11,42 @@ namespace System.Runtime.Serialization { internal CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate() { - throw new NotImplementedException (); + return () => new XmlDataContractInterpreter (this).CreateXmlSerializable (); + } + } + + internal class XmlDataContractInterpreter + { + XmlDataContract contract; + + public XmlDataContractInterpreter (XmlDataContract contract) + { + this.contract = contract; + } + + public IXmlSerializable CreateXmlSerializable () + { + Type type = contract.UnderlyingType; + object value = null; + if (type.IsValueType) + value = FormatterServices.GetUninitializedObject (type); + else + value = GetConstructor ().Invoke (new object [0]); + return (IXmlSerializable) value; + } + + ConstructorInfo GetConstructor () + { + Type type = contract.UnderlyingType; + + if (type.IsValueType) + return null; + + ConstructorInfo ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Globals.EmptyTypeArray, null); + if (ctor == null) + throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.IXmlSerializableMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(type)))); + + return ctor; } } } -- 2.25.1