You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
committed by
Jo Shields
parent
aa7da660d6
commit
c042cd0c52
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace System.Runtime.Serialization
|
||||
{
|
||||
internal partial class XmlDataContract
|
||||
{
|
||||
internal CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user