public string GetSchemaArrayName() { XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo)_itemInfo[0]; if (einfo.MappedType != null) { return(TypeTranslator.GetArrayName(einfo.MappedType.XmlType)); } else { return(TypeTranslator.GetArrayName(einfo.TypeData.XmlType)); } }
protected void ParseWsdlArrayType(XmlAttribute attr) { if (attr.NamespaceURI == wsdlNS && attr.LocalName == arrayType) { string ns = "", type, dimensions; TypeTranslator.ParseArrayType(attr.Value, out type, out ns, out dimensions); if (ns != "") { ns = Reader.LookupNamespace(ns) + ":"; } attr.Value = ns + type + dimensions; } }
XmlTypeMapping ImportPrimitiveMapping(Type type, string defaultNamespace) { TypeData typeData = TypeTranslator.GetTypeData(type); XmlTypeMapping map = helper.GetRegisteredClrType(type, GetTypeNamespace(typeData, defaultNamespace)); if (map != null) { return(map); } map = CreateTypeMapping(typeData, null, defaultNamespace); helper.RegisterClrType(map, type, map.Namespace); return(map); }
public TypeData(Type type, string elementName, bool isPrimitive, TypeData mappedType, XmlSchemaPatternFacet facet) { this.hasPublicConstructor = true; base..ctor(); if (type.IsGenericTypeDefinition) { throw new InvalidOperationException("Generic type definition cannot be used in serialization. Only specific generic types can be used."); } this.mappedType = mappedType; this.facet = facet; this.type = type; this.typeName = type.Name; this.fullTypeName = type.FullName.Replace('+', '.'); if (isPrimitive) { this.sType = SchemaTypes.Primitive; } else if (type.IsEnum) { this.sType = SchemaTypes.Enum; } else if (typeof(IXmlSerializable).IsAssignableFrom(type)) { this.sType = SchemaTypes.XmlSerializable; } else if (typeof(XmlNode).IsAssignableFrom(type)) { this.sType = SchemaTypes.XmlNode; } else if (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type)) { this.sType = SchemaTypes.Array; } else { this.sType = SchemaTypes.Class; } if (this.IsListType) { this.elementName = TypeTranslator.GetArrayName(this.ListItemTypeData.XmlType); } else { this.elementName = elementName; } if (this.sType == SchemaTypes.Array || this.sType == SchemaTypes.Class) { this.hasPublicConstructor = (!type.IsInterface && (type.IsArray || type.GetConstructor(Type.EmptyTypes) != null || type.IsAbstract || type.IsValueType)); } }
XmlTypeMapping ImportListMapping(Type type, string defaultNamespace) { TypeData typeData = TypeTranslator.GetTypeData(type); XmlTypeMapping map = helper.GetRegisteredClrType(type, XmlSerializer.EncodingNamespace); if (map != null) { return(map); } ListMap obmap = new ListMap(); TypeData itemTypeData = typeData.ListItemTypeData; map = CreateTypeMapping(typeData, "Array", XmlSerializer.EncodingNamespace); helper.RegisterClrType(map, type, XmlSerializer.EncodingNamespace); map.MultiReferenceType = true; map.ObjectMap = obmap; XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo(null, itemTypeData); if (elem.TypeData.IsComplexType) { elem.MappedType = ImportTypeMapping(typeData.ListItemType, defaultNamespace); elem.TypeData = elem.MappedType.TypeData; } elem.ElementName = "Item"; elem.Namespace = string.Empty; elem.IsNullable = true; // By default, items are nullable XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList(); list.Add(elem); obmap.ItemInfo = list; XmlTypeMapping objMap = ImportTypeMapping(typeof(object), defaultNamespace); objMap.DerivedTypes.Add(map); // Register any of the including types as a derived class of object SoapIncludeAttribute[] includes = (SoapIncludeAttribute[])type.GetCustomAttributes(typeof(SoapIncludeAttribute), false); for (int i = 0; i < includes.Length; i++) { Type includedType = includes[i].Type; objMap.DerivedTypes.Add(ImportTypeMapping(includedType, defaultNamespace)); } return(map); }
public XmlTypeMapping ImportTypeMapping(Type type, XmlRootAttribute root, string defaultNamespace) { if (type == null) { throw new ArgumentNullException("type"); } if (type == typeof(void)) { throw new InvalidOperationException("Type " + type.Name + " may not be serialized."); } if (defaultNamespace == null) { defaultNamespace = initialDefaultNamespace; } if (defaultNamespace == null) { defaultNamespace = string.Empty; } XmlTypeMapping map; switch (TypeTranslator.GetTypeData(type).SchemaType) { case SchemaTypes.Class: map = ImportClassMapping(type, root, defaultNamespace); break; case SchemaTypes.Array: map = ImportListMapping(type, root, defaultNamespace, null, 0); break; case SchemaTypes.XmlNode: map = ImportXmlNodeMapping(type, root, defaultNamespace); break; case SchemaTypes.Primitive: map = ImportPrimitiveMapping(type, root, defaultNamespace); break; case SchemaTypes.Enum: map = ImportEnumMapping(type, root, defaultNamespace); break; case SchemaTypes.XmlSerializable: map = ImportXmlSerializableMapping(type, root, defaultNamespace); break; default: throw new NotSupportedException("Type " + type.FullName + " not supported for XML stialization"); } map.RelatedMaps = relatedMaps; map.Format = SerializationFormat.Literal; map.Source = new XmlTypeSerializationSource(type, root, attributeOverrides, defaultNamespace, includedTypes); if (allowPrivateTypes) { map.Source.CanBeGenerated = false; } return(map); }
public XmlTypeMapping ImportTypeMapping(Type type, string defaultNamespace) { if (type == null) { throw new ArgumentNullException("type"); } if (type == typeof(void)) { throw new InvalidOperationException("Type " + type.Name + " may not be serialized."); } return(ImportTypeMapping(TypeTranslator.GetTypeData(type), defaultNamespace)); }
internal void AddKeyHash(StringBuilder sb) { sb.Append("XA "); KeyHelper.AddField(sb, 1, this.xmlIgnore); KeyHelper.AddField(sb, 2, this.xmlns); KeyHelper.AddField(sb, 3, this.xmlAnyAttribute != null); this.xmlAnyElements.AddKeyHash(sb); this.xmlArrayItems.AddKeyHash(sb); this.xmlElements.AddKeyHash(sb); if (this.xmlArray != null) { this.xmlArray.AddKeyHash(sb); } if (this.xmlAttribute != null) { this.xmlAttribute.AddKeyHash(sb); } if (this.xmlDefaultValue == null) { sb.Append("n"); } else if (!(this.xmlDefaultValue is DBNull)) { string str = XmlCustomFormatter.ToXmlString(TypeTranslator.GetTypeData(this.xmlDefaultValue.GetType()), this.xmlDefaultValue); sb.Append("v" + str); } if (this.xmlEnum != null) { this.xmlEnum.AddKeyHash(sb); } if (this.xmlRoot != null) { this.xmlRoot.AddKeyHash(sb); } if (this.xmlText != null) { this.xmlText.AddKeyHash(sb); } if (this.xmlType != null) { this.xmlType.AddKeyHash(sb); } if (this.xmlChoiceIdentifier != null) { this.xmlChoiceIdentifier.AddKeyHash(sb); } sb.Append("|"); }
ICollection GetReflectionMembers(Type type) { ArrayList members = new ArrayList(); PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo prop in properties) { if (!prop.CanRead) { continue; } if (!prop.CanWrite && (TypeTranslator.GetTypeData(prop.PropertyType).SchemaType != SchemaTypes.Array || prop.PropertyType.IsArray)) { continue; } SoapAttributes atts = attributeOverrides[type, prop.Name]; if (atts == null) { atts = new SoapAttributes(prop); } if (atts.SoapIgnore) { continue; } XmlReflectionMember member = new XmlReflectionMember(prop.Name, prop.PropertyType, atts); members.Add(member); } FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo field in fields) { SoapAttributes atts = attributeOverrides[type, field.Name]; if (atts == null) { atts = new SoapAttributes(field); } if (atts.SoapIgnore) { continue; } XmlReflectionMember member = new XmlReflectionMember(field.Name, field.FieldType, atts); members.Add(member); } return(members); }
protected override void GenerateAttributeMember(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberAttribute attinfo, string defaultNamespace, bool forceUseMemberName) { CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Xml.Serialization.SoapAttribute"); if (attinfo.Name != attinfo.AttributeName) { att.Arguments.Add(GetArg(attinfo.AttributeName)); } if (attinfo.Namespace != defaultNamespace) { att.Arguments.Add(GetArg("Namespace", attinfo.Namespace)); } if (!TypeTranslator.IsDefaultPrimitiveTpeData(attinfo.TypeData)) { att.Arguments.Add(GetArg("DataType", attinfo.TypeData.XmlType)); } attributes.Add(att); }
protected override void GenerateElementInfoMember(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, XmlTypeMapElementInfo einfo, TypeData defaultType, string defaultNamespace, bool addAlwaysAttr, bool forceUseMemberName) { CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Xml.Serialization.SoapElement"); if (forceUseMemberName || einfo.ElementName != member.Name) { att.Arguments.Add(GetArg(einfo.ElementName)); } // if (einfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", true)); MS seems to ignore this if (!TypeTranslator.IsDefaultPrimitiveTpeData(einfo.TypeData)) { att.Arguments.Add(GetArg("DataType", einfo.TypeData.XmlType)); } if (addAlwaysAttr || att.Arguments.Count > 0) { attributes.Add(att); } }
XmlTypeMapping ImportXmlNodeMapping(Type type, XmlRootAttribute root, string defaultNamespace) { XmlTypeMapping map = helper.GetRegisteredClrType(type, GetTypeNamespace(TypeTranslator.GetTypeData(type), root, defaultNamespace)); if (map != null) { return(map); } // Registers the maps for XmlNode and XmlElement XmlTypeMapping nodeMap = CreateTypeMapping(TypeTranslator.GetTypeData(typeof(XmlNode)), root, null, defaultNamespace); helper.RegisterClrType(nodeMap, typeof(XmlNode), nodeMap.XmlTypeNamespace); XmlTypeMapping elemMap = CreateTypeMapping(TypeTranslator.GetTypeData(typeof(XmlElement)), root, null, defaultNamespace); helper.RegisterClrType(elemMap, typeof(XmlElement), elemMap.XmlTypeNamespace); XmlTypeMapping textMap = CreateTypeMapping(TypeTranslator.GetTypeData(typeof(XmlText)), root, null, defaultNamespace); helper.RegisterClrType(textMap, typeof(XmlText), textMap.XmlTypeNamespace); XmlTypeMapping docMap = CreateTypeMapping(TypeTranslator.GetTypeData(typeof(XmlDocument)), root, null, defaultNamespace); helper.RegisterClrType(docMap, typeof(XmlDocument), textMap.XmlTypeNamespace); XmlTypeMapping obmap = ImportTypeMapping(typeof(object)); obmap.DerivedTypes.Add(nodeMap); obmap.DerivedTypes.Add(elemMap); obmap.DerivedTypes.Add(textMap); obmap.DerivedTypes.Add(docMap); nodeMap.DerivedTypes.Add(elemMap); nodeMap.DerivedTypes.Add(textMap); nodeMap.DerivedTypes.Add(docMap); map = helper.GetRegisteredClrType(type, GetTypeNamespace(TypeTranslator.GetTypeData(type), root, defaultNamespace)); if (map == null) { throw new InvalidOperationException("Objects of type '" + type + "' can't be serialized"); } return(map); }
protected void WriteTypedPrimitive(string name, string ns, object o, bool xsiType) { string value; TypeData td = TypeTranslator.GetTypeData(o.GetType(), null, true); if (td.SchemaType != SchemaTypes.Primitive) { throw new InvalidOperationException(String.Format("The type of the argument object '{0}' is not primitive.", td.FullTypeName)); } if (name == null) { ns = td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace; name = td.XmlType; } else { name = XmlCustomFormatter.FromXmlName(name); } Writer.WriteStartElement(name, ns); if (o is XmlQualifiedName) { value = FromXmlQualifiedName((XmlQualifiedName)o); } else { value = XmlCustomFormatter.ToXmlString(td, o); } if (xsiType) { if (td.SchemaType != SchemaTypes.Primitive) { throw new InvalidOperationException(string.Format(unexpectedTypeError, o.GetType().FullName)); } WriteXsiType(td.XmlType, td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace); } WriteValue(value); Writer.WriteEndElement(); }
XmlTypeMapping ImportEnumMapping(Type type, XmlRootAttribute root, string defaultNamespace) { TypeData typeData = TypeTranslator.GetTypeData(type); XmlTypeMapping map = helper.GetRegisteredClrType(type, GetTypeNamespace(typeData, root, defaultNamespace)); if (map != null) { return(map); } map = CreateTypeMapping(typeData, root, null, defaultNamespace); helper.RegisterClrType(map, type, map.XmlTypeNamespace); string [] names = Enum.GetNames(type); ArrayList members = new ArrayList(); foreach (string name in names) { MemberInfo[] mem = type.GetMember(name); string xmlName = null; object[] atts = mem[0].GetCustomAttributes(typeof(XmlIgnoreAttribute), false); if (atts.Length > 0) { continue; } atts = mem[0].GetCustomAttributes(typeof(XmlEnumAttribute), false); if (atts.Length > 0) { xmlName = ((XmlEnumAttribute)atts[0]).Name; } if (xmlName == null) { xmlName = name; } members.Add(new EnumMap.EnumMapMember(xmlName, name)); } bool isFlags = type.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0; map.ObjectMap = new EnumMap((EnumMap.EnumMapMember[])members.ToArray(typeof(EnumMap.EnumMapMember)), isFlags); ImportTypeMapping(typeof(object)).DerivedTypes.Add(map); return(map); }
protected object ReadTypedPrimitive(XmlQualifiedName qname) { if (qname == null) { qname = GetXsiType(); } TypeData typeData = TypeTranslator.FindPrimitiveTypeData(qname.Name); if (typeData == null || typeData.SchemaType != SchemaTypes.Primitive) { // Put everything into a node array XmlNode node = Document.ReadNode(reader); XmlElement elem = node as XmlElement; if (elem == null) { return new XmlNode[] { node } } ; else { XmlNode[] nodes = new XmlNode[elem.Attributes.Count + elem.ChildNodes.Count]; int n = 0; foreach (XmlNode no in elem.Attributes) { nodes[n++] = no; } foreach (XmlNode no in elem.ChildNodes) { nodes[n++] = no; } return(nodes); } } if (typeData.Type == typeof(XmlQualifiedName)) { return(ReadNullableQualifiedName()); } return(XmlCustomFormatter.FromXmlString(typeData, Reader.ReadElementString())); }
public void AddMappingMetadata(CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, bool forceUseMemberName) { TypeData memType = member.TypeMapMember.TypeData; CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Xml.Serialization.SoapElement"); if (forceUseMemberName || (member.ElementName != member.MemberName)) { att.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(member.ElementName))); } if (!TypeTranslator.IsDefaultPrimitiveTpeData(memType)) { att.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(member.TypeName))); } if (att.Arguments.Count > 0) { metadata.Add(att); } }
private ICollection GetReflectionMembers(Type type) { ArrayList arrayList = new ArrayList(); PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo propertyInfo in properties) { if (propertyInfo.CanRead) { if (propertyInfo.CanWrite || (TypeTranslator.GetTypeData(propertyInfo.PropertyType).SchemaType == SchemaTypes.Array && !propertyInfo.PropertyType.IsArray)) { SoapAttributes soapAttributes = this.attributeOverrides[type, propertyInfo.Name]; if (soapAttributes == null) { soapAttributes = new SoapAttributes(propertyInfo); } if (!soapAttributes.SoapIgnore) { XmlReflectionMember value = new XmlReflectionMember(propertyInfo.Name, propertyInfo.PropertyType, soapAttributes); arrayList.Add(value); } } } } FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (FieldInfo fieldInfo in fields) { SoapAttributes soapAttributes2 = this.attributeOverrides[type, fieldInfo.Name]; if (soapAttributes2 == null) { soapAttributes2 = new SoapAttributes(fieldInfo); } if (!soapAttributes2.SoapIgnore) { XmlReflectionMember value2 = new XmlReflectionMember(fieldInfo.Name, fieldInfo.FieldType, soapAttributes2); arrayList.Add(value2); } } return(arrayList); }
internal void AddKeyHash(System.Text.StringBuilder sb) { sb.Append("SA "); if (soapIgnore) { sb.Append('i'); } if (soapAttribute != null) { soapAttribute.AddKeyHash(sb); } if (soapElement != null) { soapElement.AddKeyHash(sb); } if (soapEnum != null) { soapEnum.AddKeyHash(sb); } if (soapType != null) { soapType.AddKeyHash(sb); } if (soapDefaultValue == null) { sb.Append("n"); } else if (!(soapDefaultValue is System.DBNull)) { string v = XmlCustomFormatter.ToXmlString(TypeTranslator.GetTypeData(soapDefaultValue.GetType()), soapDefaultValue); sb.Append("v" + v); } sb.Append("|"); }
protected void WriteReferencedElements() { if (referencedElements == null) { return; } if (callbacks == null) { return; } while (referencedElements.Count > 0) { object o = referencedElements.Dequeue(); TypeData td = TypeTranslator.GetTypeData(o.GetType()); WriteCallbackInfo info = (WriteCallbackInfo)callbacks[o.GetType()]; if (info != null) { WriteStartElement(info.TypeName, info.TypeNs, true); Writer.WriteAttributeString("id", GetId(o, false)); if (td.SchemaType != SchemaTypes.Array) // Array use its own "arrayType" attribute { WriteXsiType(info.TypeName, info.TypeNs); } info.Callback(o); WriteEndElement(); } else if (IsPrimitiveArray(td)) { WriteArray(o, td); } } }
protected void WriteXmlAttribute(XmlNode node, object container) { XmlAttribute attr = node as XmlAttribute; if (attr == null) { throw new InvalidOperationException("The node must be either type XmlAttribute or a derived type."); } if (attr.NamespaceURI == XmlSerializer.WsdlNamespace) { // The wsdl arrayType attribute needs special handling if (attr.LocalName == "arrayType") { string ns, type, dimensions; TypeTranslator.ParseArrayType(attr.Value, out type, out ns, out dimensions); string value = GetQualifiedName(type + dimensions, ns); WriteAttribute(attr.Prefix, attr.LocalName, attr.NamespaceURI, value); return; } } WriteAttribute(attr.Prefix, attr.LocalName, attr.NamespaceURI, attr.Value); }
bool ReadList(out object resultList) { string arrayTypeAttr = Reader.GetAttribute(arrayType, soapNS); if (arrayTypeAttr == null) { arrayTypeAttr = Reader.GetAttribute(arrayType, wsdlNS); } XmlQualifiedName qn = ToXmlQualifiedName(arrayTypeAttr); int i = qn.Name.LastIndexOf('['); string dim = qn.Name.Substring(i); string itemType = qn.Name.Substring(0, i); int count = Int32.Parse(dim.Substring(1, dim.Length - 2), CultureInfo.InvariantCulture); Array list; i = itemType.IndexOf('['); if (i == -1) { i = itemType.Length; } string baseType = itemType.Substring(0, i); string arrayTypeName; if (qn.Namespace == w3SchemaNS) { arrayTypeName = TypeTranslator.GetPrimitiveTypeData(baseType).Type.FullName + itemType.Substring(i); } else { WriteCallbackInfo info = GetCallbackInfo(new XmlQualifiedName(baseType, qn.Namespace)); arrayTypeName = info.Type.FullName + itemType.Substring(i) + ", " + info.Type.Assembly.FullName; } list = Array.CreateInstance(Type.GetType(arrayTypeName), count); bool listComplete = true; if (Reader.IsEmptyElement) { readCount++; Reader.Skip(); } else { Reader.ReadStartElement(); for (int n = 0; n < count; n++) { whileIterationCount++; readCount++; Reader.MoveToContent(); string id; object item = ReadReferencingElement(itemType, qn.Namespace, out id); if (id == null) { list.SetValue(item, n); } else { AddFixup(new CollectionItemFixup(list, n, id)); listComplete = false; } } whileIterationCount = 0; Reader.ReadEndElement(); } resultList = list; return(listComplete); }
protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable) { if (o == null) { if (isNullable) { WriteNullTagEncoded(n, ns); } return; } var t = o.GetType(); WriteStartElement(n, ns, true); CheckReferenceQueue(); if (callbacks != null && callbacks.ContainsKey(o.GetType())) { WriteCallbackInfo info = (WriteCallbackInfo)callbacks[t]; if (t.IsEnum) { info.Callback(o); } else if (suppressReference) { Writer.WriteAttributeString("id", GetId(o, false)); if (ambientType != t) { WriteXsiType(info.TypeName, info.TypeNs); } info.Callback(o); } else { if (!AlreadyQueued(o)) { referencedElements.Enqueue(o); } Writer.WriteAttributeString("href", "#" + GetId(o, true)); } } else { // Must be a primitive type or array of primitives TypeData td = TypeTranslator.GetTypeData(t, null, true); if (td.SchemaType == SchemaTypes.Primitive) { if (t != ambientType) { WriteXsiType(td.XmlType, XmlSchema.Namespace); } Writer.WriteString(XmlCustomFormatter.ToXmlString(td, o)); } else if (IsPrimitiveArray(td)) { if (!AlreadyQueued(o)) { referencedElements.Enqueue(o); } Writer.WriteAttributeString("href", "#" + GetId(o, true)); } else { throw new InvalidOperationException("Invalid type: " + t.FullName); } } WriteEndElement(); }
XmlTypeMapElementInfoList ImportElementInfo(string defaultName, string defaultNamespace, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts) { XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList(); ImportTextElementInfo(list, defaultType, member, atts); if (atts.XmlElements.Count == 0 && list.Count == 0) { XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo(member, TypeTranslator.GetTypeData(defaultType)); elem.ElementName = defaultName; elem.Namespace = defaultNamespace; if (elem.TypeData.IsComplexType) { elem.MappedType = ImportTypeMapping(defaultType, null, defaultNamespace); } list.Add(elem); } bool multiType = (atts.XmlElements.Count > 1); foreach (XmlElementAttribute att in atts.XmlElements) { Type elemType = (att.Type != null) ? att.Type : defaultType; XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo(member, TypeTranslator.GetTypeData(elemType, att.DataType)); elem.ElementName = (att.ElementName != null) ? att.ElementName : defaultName; elem.Namespace = (att.Namespace != null) ? att.Namespace : defaultNamespace; elem.Form = att.Form; elem.IsNullable = att.IsNullable; if (elem.IsNullable && elem.TypeData.IsValueType) { throw new InvalidOperationException("IsNullable may not be 'true' for value type " + elem.TypeData.FullTypeName + " in member '" + defaultName + "'"); } if (elem.TypeData.IsComplexType) { if (att.DataType != null) { throw new InvalidOperationException("'" + att.DataType + "' is an invalid value for the XmlElementAttribute.DateTime property. The property may only be specified for primitive types."); } elem.MappedType = ImportTypeMapping(elemType, null, elem.Namespace); } if (att.ElementName != null) { elem.ElementName = att.ElementName; } else if (multiType) { if (elem.MappedType != null) { elem.ElementName = elem.MappedType.ElementName; } else { elem.ElementName = TypeTranslator.GetTypeData(elemType).XmlType; } } else { elem.ElementName = defaultName; } list.Add(elem); } return(list); }
public static TypeData GetTypeData(Type type) { return(TypeTranslator.GetTypeData(type, null)); }
public static TypeData GetTypeData(Type runtimeType, string xmlDataType) { Type type = runtimeType; bool flag = false; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { flag = true; type = type.GetGenericArguments()[0]; TypeData typeData = TypeTranslator.GetTypeData(type); if (typeData != null) { TypeData typeData2 = (TypeData)TypeTranslator.nullableTypes[typeData.XmlType]; if (typeData2 == null) { typeData2 = new TypeData(type, typeData.XmlType, false); typeData2.IsNullable = true; TypeTranslator.nullableTypes[typeData.XmlType] = typeData2; } return(typeData2); } } if (xmlDataType != null && xmlDataType.Length != 0) { TypeData primitiveTypeData = TypeTranslator.GetPrimitiveTypeData(xmlDataType); if (!type.IsArray || type == primitiveTypeData.Type) { return(primitiveTypeData); } TypeData typeData3 = (TypeData)TypeTranslator.primitiveArrayTypes[xmlDataType]; if (typeData3 != null) { return(typeData3); } if (primitiveTypeData.Type == type.GetElementType()) { typeData3 = new TypeData(type, TypeTranslator.GetArrayName(primitiveTypeData.XmlType), false); TypeTranslator.primitiveArrayTypes[xmlDataType] = typeData3; return(typeData3); } throw new InvalidOperationException(string.Concat(new object[] { "Cannot convert values of type '", type.GetElementType(), "' to '", xmlDataType, "'" })); } else { TypeData typeData4 = TypeTranslator.nameCache[runtimeType] as TypeData; if (typeData4 != null) { return(typeData4); } string text; if (type.IsArray) { string xmlType = TypeTranslator.GetTypeData(type.GetElementType()).XmlType; text = TypeTranslator.GetArrayName(xmlType); } else if (type.IsGenericType && !type.IsGenericTypeDefinition) { text = XmlConvert.EncodeLocalName(type.Name.Substring(0, type.Name.IndexOf('`'))) + "Of"; foreach (Type type2 in type.GetGenericArguments()) { text += ((!type2.IsArray && !type2.IsGenericType) ? CodeIdentifier.MakePascal(XmlConvert.EncodeLocalName(type2.Name)) : TypeTranslator.GetTypeData(type2).XmlType); } } else { text = XmlConvert.EncodeLocalName(type.Name); } typeData4 = new TypeData(type, text, false); if (flag) { typeData4.IsNullable = true; } TypeTranslator.nameCache[runtimeType] = typeData4; return(typeData4); } }
public static bool IsDefaultPrimitiveTpeData(TypeData primType) { return(TypeTranslator.GetDefaultPrimitiveTypeData(primType) == primType); }
public static TypeData GetPrimitiveTypeData(string typeName) { return(TypeTranslator.GetPrimitiveTypeData(typeName, false)); }
public static bool IsPrimitive(Type type) { return(TypeTranslator.GetTypeData(type).SchemaType == SchemaTypes.Primitive); }
XmlSchemaAttribute GetSchemaAttribute(XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo, bool isTypeMember) { XmlSchemaAttribute sat = new XmlSchemaAttribute(); if (attinfo.DefaultValue != System.DBNull.Value) { sat.DefaultValue = ExportDefaultValue(attinfo.TypeData, attinfo.MappedType, attinfo.DefaultValue); } else { if (!attinfo.IsOptionalValueType && attinfo.TypeData.IsValueType) { sat.Use = XmlSchemaUse.Required; } } ImportNamespace(currentSchema, attinfo.Namespace); XmlSchema memberSchema; if (attinfo.Namespace.Length == 0 && attinfo.Form != XmlSchemaForm.Qualified) { memberSchema = currentSchema; } else { memberSchema = GetSchema(attinfo.Namespace); } if (currentSchema == memberSchema || encodedFormat) { sat.Name = attinfo.AttributeName; if (isTypeMember) { sat.Form = attinfo.Form; } if (attinfo.TypeData.SchemaType == SchemaTypes.Enum) { ImportNamespace(currentSchema, attinfo.DataTypeNamespace); ExportEnumSchema(attinfo.MappedType); sat.SchemaTypeName = new XmlQualifiedName(attinfo.TypeData.XmlType, attinfo.DataTypeNamespace); } else if (attinfo.TypeData.SchemaType == SchemaTypes.Array && TypeTranslator.IsPrimitive(attinfo.TypeData.ListItemType)) { sat.SchemaType = GetSchemaSimpleListType(attinfo.TypeData); } else { sat.SchemaTypeName = new XmlQualifiedName(attinfo.TypeData.XmlType, attinfo.DataTypeNamespace); }; } else { sat.RefName = new XmlQualifiedName(attinfo.AttributeName, attinfo.Namespace); foreach (XmlSchemaObject ob in memberSchema.Items) { if (ob is XmlSchemaAttribute && ((XmlSchemaAttribute)ob).Name == attinfo.AttributeName) { return(sat); } } memberSchema.Items.Add(GetSchemaAttribute(memberSchema, attinfo, false)); } return(sat); }
object ReadTypedPrimitive(XmlQualifiedName qname, bool reportUnknown) { if (qname == null) { qname = GetXsiType(); } TypeData typeData = TypeTranslator.FindPrimitiveTypeData(qname.Name); if (typeData == null || typeData.SchemaType != SchemaTypes.Primitive) { #if MOONLIGHT // skip everything reader.Skip(); return(new Object()); #else // Put everything into a node array readCount++; XmlNode node = Document.ReadNode(reader); if (reportUnknown) { OnUnknownNode(node, null, null); } if (node.ChildNodes.Count == 0 && node.Attributes.Count == 0) { return(new Object()); } XmlElement elem = node as XmlElement; if (elem == null) { return new XmlNode[] { node } } ; else { XmlNode[] nodes = new XmlNode[elem.Attributes.Count + elem.ChildNodes.Count]; int n = 0; foreach (XmlNode no in elem.Attributes) { nodes[n++] = no; } foreach (XmlNode no in elem.ChildNodes) { nodes[n++] = no; } return(nodes); } #endif } if (typeData.Type == typeof(XmlQualifiedName)) { return(ReadNullableQualifiedName()); } readCount++; return(XmlCustomFormatter.FromXmlString(typeData, Reader.ReadElementString())); }