public static bool TryCreateBuiltInDataContract(string name, string ns, out DataContract dataContract) { dataContract = null; if (ns == DictionaryGlobals.SchemaNamespace.Value) { if (DictionaryGlobals.BooleanLocalName.Value == name) { dataContract = new BooleanDataContract(); } else if (DictionaryGlobals.SignedByteLocalName.Value == name) { dataContract = new SignedByteDataContract(); } else if (DictionaryGlobals.UnsignedByteLocalName.Value == name) { dataContract = new UnsignedByteDataContract(); } else if (DictionaryGlobals.ShortLocalName.Value == name) { dataContract = new ShortDataContract(); } else if (DictionaryGlobals.UnsignedShortLocalName.Value == name) { dataContract = new UnsignedShortDataContract(); } else if (DictionaryGlobals.IntLocalName.Value == name) { dataContract = new IntDataContract(); } else if (DictionaryGlobals.UnsignedIntLocalName.Value == name) { dataContract = new UnsignedIntDataContract(); } else if (DictionaryGlobals.LongLocalName.Value == name) { dataContract = new LongDataContract(); } else if (DictionaryGlobals.integerLocalName.Value == name) { dataContract = new IntegerDataContract(); } else if (DictionaryGlobals.positiveIntegerLocalName.Value == name) { dataContract = new PositiveIntegerDataContract(); } else if (DictionaryGlobals.negativeIntegerLocalName.Value == name) { dataContract = new NegativeIntegerDataContract(); } else if (DictionaryGlobals.nonPositiveIntegerLocalName.Value == name) { dataContract = new NonPositiveIntegerDataContract(); } else if (DictionaryGlobals.nonNegativeIntegerLocalName.Value == name) { dataContract = new NonNegativeIntegerDataContract(); } else if (DictionaryGlobals.UnsignedLongLocalName.Value == name) { dataContract = new UnsignedLongDataContract(); } else if (DictionaryGlobals.FloatLocalName.Value == name) { dataContract = new FloatDataContract(); } else if (DictionaryGlobals.DoubleLocalName.Value == name) { dataContract = new DoubleDataContract(); } else if (DictionaryGlobals.DecimalLocalName.Value == name) { dataContract = new DecimalDataContract(); } else if (DictionaryGlobals.DateTimeLocalName.Value == name) { dataContract = new DateTimeDataContract(); } else if (DictionaryGlobals.StringLocalName.Value == name) { dataContract = new StringDataContract(); } else if (DictionaryGlobals.timeLocalName.Value == name) { dataContract = new TimeDataContract(); } else if (DictionaryGlobals.dateLocalName.Value == name) { dataContract = new DateDataContract(); } else if (DictionaryGlobals.hexBinaryLocalName.Value == name) { dataContract = new HexBinaryDataContract(); } else if (DictionaryGlobals.gYearMonthLocalName.Value == name) { dataContract = new GYearMonthDataContract(); } else if (DictionaryGlobals.gYearLocalName.Value == name) { dataContract = new GYearDataContract(); } else if (DictionaryGlobals.gMonthDayLocalName.Value == name) { dataContract = new GMonthDayDataContract(); } else if (DictionaryGlobals.gDayLocalName.Value == name) { dataContract = new GDayDataContract(); } else if (DictionaryGlobals.gMonthLocalName.Value == name) { dataContract = new GMonthDataContract(); } else if (DictionaryGlobals.normalizedStringLocalName.Value == name) { dataContract = new NormalizedStringDataContract(); } else if (DictionaryGlobals.tokenLocalName.Value == name) { dataContract = new TokenDataContract(); } else if (DictionaryGlobals.languageLocalName.Value == name) { dataContract = new LanguageDataContract(); } else if (DictionaryGlobals.NameLocalName.Value == name) { dataContract = new NameDataContract(); } else if (DictionaryGlobals.NCNameLocalName.Value == name) { dataContract = new NCNameDataContract(); } else if (DictionaryGlobals.XSDIDLocalName.Value == name) { dataContract = new IDDataContract(); } else if (DictionaryGlobals.IDREFLocalName.Value == name) { dataContract = new IDREFDataContract(); } else if (DictionaryGlobals.IDREFSLocalName.Value == name) { dataContract = new IDREFSDataContract(); } else if (DictionaryGlobals.ENTITYLocalName.Value == name) { dataContract = new ENTITYDataContract(); } else if (DictionaryGlobals.ENTITIESLocalName.Value == name) { dataContract = new ENTITIESDataContract(); } else if (DictionaryGlobals.NMTOKENLocalName.Value == name) { dataContract = new NMTOKENDataContract(); } else if (DictionaryGlobals.NMTOKENSLocalName.Value == name) { dataContract = new NMTOKENDataContract(); } else if (DictionaryGlobals.ByteArrayLocalName.Value == name) { dataContract = new ByteArrayDataContract(); } else if (DictionaryGlobals.ObjectLocalName.Value == name) { dataContract = new ObjectDataContract(); } else if (DictionaryGlobals.TimeSpanLocalName.Value == name) { dataContract = new XsDurationDataContract(); } else if (DictionaryGlobals.UriLocalName.Value == name) { dataContract = new UriDataContract(); } else if (DictionaryGlobals.QNameLocalName.Value == name) { dataContract = new QNameDataContract(); } } else if (ns == DictionaryGlobals.SerializationNamespace.Value) { if (DictionaryGlobals.TimeSpanLocalName.Value == name) { dataContract = new TimeSpanDataContract(); } else if (DictionaryGlobals.GuidLocalName.Value == name) { dataContract = new GuidDataContract(); } else if (DictionaryGlobals.CharLocalName.Value == name) { dataContract = new CharDataContract(); } else if ("ArrayOfanyType" == name) { dataContract = new CollectionDataContract(typeof(Array)); } } else if (ns == DictionaryGlobals.AsmxTypesNamespace.Value) { if (DictionaryGlobals.CharLocalName.Value == name) { dataContract = new AsmxCharDataContract(); } else if (DictionaryGlobals.GuidLocalName.Value == name) { dataContract = new AsmxGuidDataContract(); } } else if (ns == "http://schemas.datacontract.org/2004/07/System.Xml") { if (name == "XmlElement") { dataContract = new XmlDataContract(typeof(XmlElement)); } else if (name == "ArrayOfXmlNode") { dataContract = new XmlDataContract(typeof(System.Xml.XmlNode[])); } } return (dataContract != null); }
public static bool TryCreateBuiltInDataContract(Type type, out DataContract dataContract) { if (type.IsEnum) { dataContract = null; return false; } dataContract = null; switch (Type.GetTypeCode(type)) { case TypeCode.Boolean: dataContract = new BooleanDataContract(); break; case TypeCode.Char: dataContract = new CharDataContract(); break; case TypeCode.SByte: dataContract = new SignedByteDataContract(); break; case TypeCode.Byte: dataContract = new UnsignedByteDataContract(); break; case TypeCode.Int16: dataContract = new ShortDataContract(); break; case TypeCode.UInt16: dataContract = new UnsignedShortDataContract(); break; case TypeCode.Int32: dataContract = new IntDataContract(); break; case TypeCode.UInt32: dataContract = new UnsignedIntDataContract(); break; case TypeCode.Int64: dataContract = new LongDataContract(); break; case TypeCode.UInt64: dataContract = new UnsignedLongDataContract(); break; case TypeCode.Single: dataContract = new FloatDataContract(); break; case TypeCode.Double: dataContract = new DoubleDataContract(); break; case TypeCode.Decimal: dataContract = new DecimalDataContract(); break; case TypeCode.DateTime: dataContract = new DateTimeDataContract(); break; case TypeCode.String: dataContract = new StringDataContract(); break; default: if (type == typeof(byte[])) { dataContract = new ByteArrayDataContract(); } else if (type == typeof(object)) { dataContract = new ObjectDataContract(); } else if (type == typeof(Uri)) { dataContract = new UriDataContract(); } else if (type == typeof(XmlQualifiedName)) { dataContract = new QNameDataContract(); } else if (type == typeof(TimeSpan)) { dataContract = new TimeSpanDataContract(); } else if (type == typeof(Guid)) { dataContract = new GuidDataContract(); } else if ((type == typeof(Enum)) || (type == typeof(ValueType))) { dataContract = new SpecialTypeDataContract(type, DictionaryGlobals.ObjectLocalName, DictionaryGlobals.SchemaNamespace); } else if (type == typeof(Array)) { dataContract = new CollectionDataContract(type); } else if ((type == typeof(XmlElement)) || (type == typeof(System.Xml.XmlNode[]))) { dataContract = new XmlDataContract(type); } break; } return (dataContract != null); }