internal void AddReference(XmlQualifiedName name, System.Xml.Serialization.NameTable references, string error) { if (name.Namespace != "http://www.w3.org/2001/XMLSchema") { if (references[name] != null) { throw new InvalidOperationException(Res.GetString(error, new object[] { name.Name, name.Namespace })); } references[name] = name; } }
public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides, string defaultNamespace) { this.types = new System.Xml.Serialization.NameTable(); this.nullables = new System.Xml.Serialization.NameTable(); if (defaultNamespace == null) { defaultNamespace = string.Empty; } if (attributeOverrides == null) { attributeOverrides = new SoapAttributeOverrides(); } this.attributeOverrides = attributeOverrides; this.defaultNs = defaultNamespace; this.typeScope = new TypeScope(); this.modelScope = new ModelScope(this.typeScope); }
public XmlReflectionImporter(XmlAttributeOverrides attributeOverrides, string defaultNamespace) { this.defaultAttributes = new XmlAttributes(); this.types = new System.Xml.Serialization.NameTable(); this.nullables = new System.Xml.Serialization.NameTable(); this.elements = new System.Xml.Serialization.NameTable(); this.anonymous = new Hashtable(); this.choiceNum = 1; if (defaultNamespace == null) { defaultNamespace = string.Empty; } if (attributeOverrides == null) { attributeOverrides = new XmlAttributeOverrides(); } this.attributeOverrides = attributeOverrides; this.defaultNs = defaultNamespace; this.typeScope = new TypeScope(); this.modelScope = new ModelScope(this.typeScope); }
private void CheckAmbiguousChoice(XmlAttributes a, Type accessorType, string accessorName) { Hashtable hashtable = new Hashtable(); XmlElementAttributes xmlElements = a.XmlElements; if (((xmlElements != null) && (xmlElements.Count >= 2)) && (a.XmlChoiceIdentifier == null)) { for (int i = 0; i < xmlElements.Count; i++) { Type key = (xmlElements[i].Type == null) ? accessorType : xmlElements[i].Type; if (hashtable.Contains(key)) { throw new InvalidOperationException(Res.GetString("XmlChoiceIdentiferMissing", new object[] { typeof(XmlChoiceIdentifierAttribute).Name, accessorName })); } hashtable.Add(key, false); } } if (hashtable.Contains(typeof(XmlElement)) && (a.XmlAnyElements.Count > 0)) { throw new InvalidOperationException(Res.GetString("XmlChoiceIdentiferMissing", new object[] { typeof(XmlChoiceIdentifierAttribute).Name, accessorName })); } XmlArrayItemAttributes xmlArrayItems = a.XmlArrayItems; if ((xmlArrayItems != null) && (xmlArrayItems.Count >= 2)) { System.Xml.Serialization.NameTable table = new System.Xml.Serialization.NameTable(); for (int j = 0; j < xmlArrayItems.Count; j++) { Type type2 = (xmlArrayItems[j].Type == null) ? accessorType : xmlArrayItems[j].Type; string str = xmlArrayItems[j].NestingLevel.ToString(CultureInfo.InvariantCulture); XmlArrayItemAttribute attribute = (XmlArrayItemAttribute) table[type2.FullName, str]; if (attribute != null) { throw new InvalidOperationException(Res.GetString("XmlArrayItemAmbiguousTypes", new object[] { accessorName, attribute.ElementName, xmlArrayItems[j].ElementName, typeof(XmlElementAttribute).Name, typeof(XmlChoiceIdentifierAttribute).Name, accessorName })); } table[type2.FullName, str] = xmlArrayItems[j]; } } }
private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, string ns, Type choiceIdentifierType, bool rpc, bool openModel, RecursionLimiter limiter) { XmlSchemaForm qualified = XmlSchemaForm.Qualified; int arrayNestingLevel = this.arrayNestingLevel; int order = -1; XmlArrayItemAttributes savedArrayItemAttributes = this.savedArrayItemAttributes; string savedArrayNamespace = this.savedArrayNamespace; this.arrayNestingLevel = 0; this.savedArrayItemAttributes = null; this.savedArrayNamespace = null; Type fieldType = model.FieldType; string name = model.Name; ArrayList list = new ArrayList(); System.Xml.Serialization.NameTable scope = new System.Xml.Serialization.NameTable(); accessor.TypeDesc = this.typeScope.GetTypeDesc(fieldType); XmlAttributeFlags xmlFlags = a.XmlFlags; accessor.Ignore = a.XmlIgnore; if (rpc) { this.CheckTopLevelAttributes(a, name); } else { this.CheckAmbiguousChoice(a, fieldType, name); } XmlAttributeFlags flags2 = XmlAttributeFlags.ChoiceIdentifier | XmlAttributeFlags.AnyElements | XmlAttributeFlags.Elements | XmlAttributeFlags.Text; XmlAttributeFlags flags3 = XmlAttributeFlags.AnyAttribute | XmlAttributeFlags.Attribute; XmlAttributeFlags flags4 = XmlAttributeFlags.ArrayItems | XmlAttributeFlags.Array; if (((xmlFlags & flags4) != ((XmlAttributeFlags) 0)) && (fieldType == typeof(byte[]))) { accessor.TypeDesc = this.typeScope.GetArrayTypeDesc(fieldType); } if (a.XmlChoiceIdentifier != null) { accessor.ChoiceIdentifier = new ChoiceIdentifierAccessor(); accessor.ChoiceIdentifier.MemberName = a.XmlChoiceIdentifier.MemberName; accessor.ChoiceIdentifier.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(choiceIdentifierType), ns, ImportContext.Element, string.Empty, null, limiter); this.CheckChoiceIdentifierMapping((EnumMapping) accessor.ChoiceIdentifier.Mapping); } if (accessor.TypeDesc.IsArrayLike) { Type arrayElementType = TypeScope.GetArrayElementType(fieldType, model.FieldTypeDesc.FullName + "." + model.Name); if ((xmlFlags & flags3) != ((XmlAttributeFlags) 0)) { if ((xmlFlags & flags3) != xmlFlags) { throw new InvalidOperationException(Res.GetString("XmlIllegalAttributesArrayAttribute")); } if (((a.XmlAttribute != null) && !accessor.TypeDesc.ArrayElementTypeDesc.IsPrimitive) && !accessor.TypeDesc.ArrayElementTypeDesc.IsEnum) { if (accessor.TypeDesc.ArrayElementTypeDesc.Kind == TypeKind.Serializable) { throw new InvalidOperationException(Res.GetString("XmlIllegalAttrOrTextInterface", new object[] { name, accessor.TypeDesc.ArrayElementTypeDesc.FullName, typeof(IXmlSerializable).Name })); } throw new InvalidOperationException(Res.GetString("XmlIllegalAttrOrText", new object[] { name, accessor.TypeDesc.ArrayElementTypeDesc.FullName })); } bool repeats = (a.XmlAttribute != null) && (accessor.TypeDesc.ArrayElementTypeDesc.IsPrimitive || accessor.TypeDesc.ArrayElementTypeDesc.IsEnum); if (a.XmlAnyAttribute != null) { a.XmlAttribute = new XmlAttributeAttribute(); } AttributeAccessor accessor2 = new AttributeAccessor(); Type type = (a.XmlAttribute.Type == null) ? arrayElementType : a.XmlAttribute.Type; this.typeScope.GetTypeDesc(type); accessor2.Name = Accessor.EscapeQName((a.XmlAttribute.AttributeName.Length == 0) ? name : a.XmlAttribute.AttributeName); accessor2.Namespace = (a.XmlAttribute.Namespace == null) ? ns : a.XmlAttribute.Namespace; accessor2.Form = a.XmlAttribute.Form; if ((accessor2.Form == XmlSchemaForm.None) && (ns != accessor2.Namespace)) { accessor2.Form = XmlSchemaForm.Qualified; } accessor2.CheckSpecial(); CheckForm(accessor2.Form, ns != accessor2.Namespace); accessor2.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type), ns, ImportContext.Attribute, a.XmlAttribute.DataType, null, repeats, false, limiter); accessor2.IsList = repeats; accessor2.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); accessor2.Any = a.XmlAnyAttribute != null; if ((accessor2.Form == XmlSchemaForm.Qualified) && (accessor2.Namespace != ns)) { if (this.xsdAttributes == null) { this.xsdAttributes = new System.Xml.Serialization.NameTable(); } accessor2 = (AttributeAccessor) this.ReconcileAccessor(accessor2, this.xsdAttributes); } accessor.Attribute = accessor2; } else if ((xmlFlags & flags2) != ((XmlAttributeFlags) 0)) { if ((xmlFlags & flags2) != xmlFlags) { throw new InvalidOperationException(Res.GetString("XmlIllegalElementsArrayAttribute")); } if (a.XmlText != null) { TextAccessor accessor3 = new TextAccessor(); Type type4 = (a.XmlText.Type == null) ? arrayElementType : a.XmlText.Type; TypeDesc typeDesc = this.typeScope.GetTypeDesc(type4); accessor3.Name = name; accessor3.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type4), ns, ImportContext.Text, a.XmlText.DataType, null, true, false, limiter); if (!(accessor3.Mapping is SpecialMapping) && (typeDesc != this.typeScope.GetTypeDesc(typeof(string)))) { throw new InvalidOperationException(Res.GetString("XmlIllegalArrayTextAttribute", new object[] { name })); } accessor.Text = accessor3; } if (((a.XmlText == null) && (a.XmlElements.Count == 0)) && (a.XmlAnyElements.Count == 0)) { a.XmlElements.Add(CreateElementAttribute(accessor.TypeDesc)); } for (int i = 0; i < a.XmlElements.Count; i++) { ElementAccessor accessor4; XmlElementAttribute attribute = a.XmlElements[i]; Type type5 = (attribute.Type == null) ? arrayElementType : attribute.Type; TypeDesc desc2 = this.typeScope.GetTypeDesc(type5); TypeModel typeModel = this.modelScope.GetTypeModel(type5); accessor4 = new ElementAccessor { Namespace = rpc ? null : ((attribute.Namespace == null) ? ns : attribute.Namespace), Mapping = this.ImportTypeMapping(typeModel, rpc ? ns : accessor4.Namespace, ImportContext.Element, attribute.DataType, null, limiter) }; if (a.XmlElements.Count == 1) { accessor4.Name = XmlConvert.EncodeLocalName((attribute.ElementName.Length == 0) ? name : attribute.ElementName); } else { accessor4.Name = (attribute.ElementName.Length == 0) ? accessor4.Mapping.DefaultElementName : XmlConvert.EncodeLocalName(attribute.ElementName); } accessor4.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); if ((attribute.IsNullableSpecified && !attribute.IsNullable) && typeModel.TypeDesc.IsOptionalValue) { throw new InvalidOperationException(Res.GetString("XmlInvalidNotNullable", new object[] { typeModel.TypeDesc.BaseTypeDesc.FullName, "XmlElement" })); } accessor4.IsNullable = attribute.IsNullableSpecified ? attribute.IsNullable : typeModel.TypeDesc.IsOptionalValue; accessor4.Form = rpc ? XmlSchemaForm.Unqualified : ((attribute.Form == XmlSchemaForm.None) ? qualified : attribute.Form); CheckNullable(accessor4.IsNullable, desc2, accessor4.Mapping); if (!rpc) { CheckForm(accessor4.Form, ns != accessor4.Namespace); accessor4 = this.ReconcileLocalAccessor(accessor4, ns); } if (attribute.Order != -1) { if ((attribute.Order != order) && (order != -1)) { throw new InvalidOperationException(Res.GetString("XmlSequenceMatch", new object[] { "Order" })); } order = attribute.Order; } AddUniqueAccessor(scope, accessor4); list.Add(accessor4); } System.Xml.Serialization.NameTable table2 = new System.Xml.Serialization.NameTable(); for (int j = 0; j < a.XmlAnyElements.Count; j++) { XmlAnyElementAttribute attribute2 = a.XmlAnyElements[j]; Type c = typeof(IXmlSerializable).IsAssignableFrom(arrayElementType) ? arrayElementType : (typeof(XmlNode).IsAssignableFrom(arrayElementType) ? arrayElementType : typeof(XmlElement)); if (!arrayElementType.IsAssignableFrom(c)) { throw new InvalidOperationException(Res.GetString("XmlIllegalAnyElement", new object[] { arrayElementType.FullName })); } string str3 = (attribute2.Name.Length == 0) ? attribute2.Name : XmlConvert.EncodeLocalName(attribute2.Name); string str4 = attribute2.NamespaceSpecified ? attribute2.Namespace : null; if (table2[str3, str4] == null) { table2[str3, str4] = attribute2; if (scope[str3, (str4 == null) ? ns : str4] != null) { throw new InvalidOperationException(Res.GetString("XmlAnyElementDuplicate", new object[] { name, attribute2.Name, (attribute2.Namespace == null) ? "null" : attribute2.Namespace })); } ElementAccessor accessor5 = new ElementAccessor { Name = str3, Namespace = (str4 == null) ? ns : str4, Any = true, AnyNamespaces = str4 }; TypeDesc desc3 = this.typeScope.GetTypeDesc(c); TypeModel model3 = this.modelScope.GetTypeModel(c); if (accessor5.Name.Length > 0) { model3.TypeDesc.IsMixed = true; } accessor5.Mapping = this.ImportTypeMapping(model3, accessor5.Namespace, ImportContext.Element, string.Empty, null, limiter); accessor5.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); accessor5.IsNullable = false; accessor5.Form = qualified; CheckNullable(accessor5.IsNullable, desc3, accessor5.Mapping); if (!rpc) { CheckForm(accessor5.Form, ns != accessor5.Namespace); accessor5 = this.ReconcileLocalAccessor(accessor5, ns); } scope.Add(accessor5.Name, accessor5.Namespace, accessor5); list.Add(accessor5); if (attribute2.Order != -1) { if ((attribute2.Order != order) && (order != -1)) { throw new InvalidOperationException(Res.GetString("XmlSequenceMatch", new object[] { "Order" })); } order = attribute2.Order; } } } } else { if (((xmlFlags & flags4) != ((XmlAttributeFlags) 0)) && ((xmlFlags & flags4) != xmlFlags)) { throw new InvalidOperationException(Res.GetString("XmlIllegalArrayArrayAttribute")); } TypeDesc desc4 = this.typeScope.GetTypeDesc(arrayElementType); if (a.XmlArray == null) { a.XmlArray = CreateArrayAttribute(accessor.TypeDesc); } if (CountAtLevel(a.XmlArrayItems, this.arrayNestingLevel) == 0) { a.XmlArrayItems.Add(CreateArrayItemAttribute(desc4, this.arrayNestingLevel)); } ElementAccessor accessor6 = new ElementAccessor { Name = XmlConvert.EncodeLocalName((a.XmlArray.ElementName.Length == 0) ? name : a.XmlArray.ElementName), Namespace = rpc ? null : ((a.XmlArray.Namespace == null) ? ns : a.XmlArray.Namespace) }; this.savedArrayItemAttributes = a.XmlArrayItems; this.savedArrayNamespace = accessor6.Namespace; ArrayMapping mapping = this.ImportArrayLikeMapping(this.modelScope.GetArrayModel(fieldType), ns, limiter); accessor6.Mapping = mapping; accessor6.IsNullable = a.XmlArray.IsNullable; accessor6.Form = rpc ? XmlSchemaForm.Unqualified : ((a.XmlArray.Form == XmlSchemaForm.None) ? qualified : a.XmlArray.Form); order = a.XmlArray.Order; CheckNullable(accessor6.IsNullable, accessor.TypeDesc, accessor6.Mapping); if (!rpc) { CheckForm(accessor6.Form, ns != accessor6.Namespace); accessor6 = this.ReconcileLocalAccessor(accessor6, ns); } this.savedArrayItemAttributes = null; this.savedArrayNamespace = null; AddUniqueAccessor(scope, accessor6); list.Add(accessor6); } } else if (!accessor.TypeDesc.IsVoid) { XmlAttributeFlags flags5 = XmlAttributeFlags.XmlnsDeclarations | XmlAttributeFlags.ChoiceIdentifier | XmlAttributeFlags.AnyElements | XmlAttributeFlags.Attribute | XmlAttributeFlags.Elements | XmlAttributeFlags.Text; if ((xmlFlags & flags5) != xmlFlags) { throw new InvalidOperationException(Res.GetString("XmlIllegalAttribute")); } if (accessor.TypeDesc.IsPrimitive || accessor.TypeDesc.IsEnum) { if (a.XmlAnyElements.Count > 0) { throw new InvalidOperationException(Res.GetString("XmlIllegalAnyElement", new object[] { accessor.TypeDesc.FullName })); } if (a.XmlAttribute != null) { if (a.XmlElements.Count > 0) { throw new InvalidOperationException(Res.GetString("XmlIllegalAttribute")); } if (a.XmlAttribute.Type != null) { throw new InvalidOperationException(Res.GetString("XmlIllegalType", new object[] { "XmlAttribute" })); } AttributeAccessor accessor7 = new AttributeAccessor { Name = Accessor.EscapeQName((a.XmlAttribute.AttributeName.Length == 0) ? name : a.XmlAttribute.AttributeName), Namespace = (a.XmlAttribute.Namespace == null) ? ns : a.XmlAttribute.Namespace, Form = a.XmlAttribute.Form }; if ((accessor7.Form == XmlSchemaForm.None) && (ns != accessor7.Namespace)) { accessor7.Form = XmlSchemaForm.Qualified; } accessor7.CheckSpecial(); CheckForm(accessor7.Form, ns != accessor7.Namespace); accessor7.Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(fieldType), ns, ImportContext.Attribute, a.XmlAttribute.DataType, null, limiter); accessor7.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); accessor7.Any = a.XmlAnyAttribute != null; if ((accessor7.Form == XmlSchemaForm.Qualified) && (accessor7.Namespace != ns)) { if (this.xsdAttributes == null) { this.xsdAttributes = new System.Xml.Serialization.NameTable(); } accessor7 = (AttributeAccessor) this.ReconcileAccessor(accessor7, this.xsdAttributes); } accessor.Attribute = accessor7; } else { if (a.XmlText != null) { if ((a.XmlText.Type != null) && (a.XmlText.Type != fieldType)) { throw new InvalidOperationException(Res.GetString("XmlIllegalType", new object[] { "XmlText" })); } TextAccessor accessor8 = new TextAccessor { Name = name, Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(fieldType), ns, ImportContext.Text, a.XmlText.DataType, null, limiter) }; accessor.Text = accessor8; } else if (a.XmlElements.Count == 0) { a.XmlElements.Add(CreateElementAttribute(accessor.TypeDesc)); } for (int k = 0; k < a.XmlElements.Count; k++) { XmlElementAttribute attribute3 = a.XmlElements[k]; if ((attribute3.Type != null) && (this.typeScope.GetTypeDesc(attribute3.Type) != accessor.TypeDesc)) { throw new InvalidOperationException(Res.GetString("XmlIllegalType", new object[] { "XmlElement" })); } ElementAccessor accessor9 = new ElementAccessor { Name = XmlConvert.EncodeLocalName((attribute3.ElementName.Length == 0) ? name : attribute3.ElementName), Namespace = rpc ? null : ((attribute3.Namespace == null) ? ns : attribute3.Namespace) }; TypeModel model4 = this.modelScope.GetTypeModel(fieldType); accessor9.Mapping = this.ImportTypeMapping(model4, rpc ? ns : accessor9.Namespace, ImportContext.Element, attribute3.DataType, null, limiter); if (accessor9.Mapping.TypeDesc.Kind == TypeKind.Node) { accessor9.Any = true; } accessor9.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); if ((attribute3.IsNullableSpecified && !attribute3.IsNullable) && model4.TypeDesc.IsOptionalValue) { throw new InvalidOperationException(Res.GetString("XmlInvalidNotNullable", new object[] { model4.TypeDesc.BaseTypeDesc.FullName, "XmlElement" })); } accessor9.IsNullable = attribute3.IsNullableSpecified ? attribute3.IsNullable : model4.TypeDesc.IsOptionalValue; accessor9.Form = rpc ? XmlSchemaForm.Unqualified : ((attribute3.Form == XmlSchemaForm.None) ? qualified : attribute3.Form); CheckNullable(accessor9.IsNullable, accessor.TypeDesc, accessor9.Mapping); if (!rpc) { CheckForm(accessor9.Form, ns != accessor9.Namespace); accessor9 = this.ReconcileLocalAccessor(accessor9, ns); } if (attribute3.Order != -1) { if ((attribute3.Order != order) && (order != -1)) { throw new InvalidOperationException(Res.GetString("XmlSequenceMatch", new object[] { "Order" })); } order = attribute3.Order; } AddUniqueAccessor(scope, accessor9); list.Add(accessor9); } } } else if (a.Xmlns) { if (xmlFlags != XmlAttributeFlags.XmlnsDeclarations) { throw new InvalidOperationException(Res.GetString("XmlSoleXmlnsAttribute")); } if (fieldType != typeof(XmlSerializerNamespaces)) { throw new InvalidOperationException(Res.GetString("XmlXmlnsInvalidType", new object[] { name, fieldType.FullName, typeof(XmlSerializerNamespaces).FullName })); } accessor.Xmlns = new XmlnsAccessor(); accessor.Ignore = true; } else { if ((a.XmlAttribute != null) || (a.XmlText != null)) { if (accessor.TypeDesc.Kind == TypeKind.Serializable) { throw new InvalidOperationException(Res.GetString("XmlIllegalAttrOrTextInterface", new object[] { name, accessor.TypeDesc.FullName, typeof(IXmlSerializable).Name })); } throw new InvalidOperationException(Res.GetString("XmlIllegalAttrOrText", new object[] { name, accessor.TypeDesc })); } if ((a.XmlElements.Count == 0) && (a.XmlAnyElements.Count == 0)) { a.XmlElements.Add(CreateElementAttribute(accessor.TypeDesc)); } for (int m = 0; m < a.XmlElements.Count; m++) { XmlElementAttribute attribute4 = a.XmlElements[m]; Type type7 = (attribute4.Type == null) ? fieldType : attribute4.Type; TypeDesc desc5 = this.typeScope.GetTypeDesc(type7); ElementAccessor accessor10 = new ElementAccessor(); TypeModel model5 = this.modelScope.GetTypeModel(type7); accessor10.Namespace = rpc ? null : ((attribute4.Namespace == null) ? ns : attribute4.Namespace); accessor10.Mapping = this.ImportTypeMapping(model5, rpc ? ns : accessor10.Namespace, ImportContext.Element, attribute4.DataType, null, false, openModel, limiter); if (a.XmlElements.Count == 1) { accessor10.Name = XmlConvert.EncodeLocalName((attribute4.ElementName.Length == 0) ? name : attribute4.ElementName); } else { accessor10.Name = (attribute4.ElementName.Length == 0) ? accessor10.Mapping.DefaultElementName : XmlConvert.EncodeLocalName(attribute4.ElementName); } accessor10.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); if ((attribute4.IsNullableSpecified && !attribute4.IsNullable) && model5.TypeDesc.IsOptionalValue) { throw new InvalidOperationException(Res.GetString("XmlInvalidNotNullable", new object[] { model5.TypeDesc.BaseTypeDesc.FullName, "XmlElement" })); } accessor10.IsNullable = attribute4.IsNullableSpecified ? attribute4.IsNullable : model5.TypeDesc.IsOptionalValue; accessor10.Form = rpc ? XmlSchemaForm.Unqualified : ((attribute4.Form == XmlSchemaForm.None) ? qualified : attribute4.Form); CheckNullable(accessor10.IsNullable, desc5, accessor10.Mapping); if (!rpc) { CheckForm(accessor10.Form, ns != accessor10.Namespace); accessor10 = this.ReconcileLocalAccessor(accessor10, ns); } if (attribute4.Order != -1) { if ((attribute4.Order != order) && (order != -1)) { throw new InvalidOperationException(Res.GetString("XmlSequenceMatch", new object[] { "Order" })); } order = attribute4.Order; } AddUniqueAccessor(scope, accessor10); list.Add(accessor10); } System.Xml.Serialization.NameTable table3 = new System.Xml.Serialization.NameTable(); for (int n = 0; n < a.XmlAnyElements.Count; n++) { XmlAnyElementAttribute attribute5 = a.XmlAnyElements[n]; Type type8 = typeof(IXmlSerializable).IsAssignableFrom(fieldType) ? fieldType : (typeof(XmlNode).IsAssignableFrom(fieldType) ? fieldType : typeof(XmlElement)); if (!fieldType.IsAssignableFrom(type8)) { throw new InvalidOperationException(Res.GetString("XmlIllegalAnyElement", new object[] { fieldType.FullName })); } string str5 = (attribute5.Name.Length == 0) ? attribute5.Name : XmlConvert.EncodeLocalName(attribute5.Name); string str6 = attribute5.NamespaceSpecified ? attribute5.Namespace : null; if (table3[str5, str6] == null) { table3[str5, str6] = attribute5; if (scope[str5, (str6 == null) ? ns : str6] != null) { throw new InvalidOperationException(Res.GetString("XmlAnyElementDuplicate", new object[] { name, attribute5.Name, (attribute5.Namespace == null) ? "null" : attribute5.Namespace })); } ElementAccessor accessor11 = new ElementAccessor { Name = str5, Namespace = (str6 == null) ? ns : str6, Any = true, AnyNamespaces = str6 }; TypeDesc desc6 = this.typeScope.GetTypeDesc(type8); TypeModel model6 = this.modelScope.GetTypeModel(type8); if (accessor11.Name.Length > 0) { model6.TypeDesc.IsMixed = true; } accessor11.Mapping = this.ImportTypeMapping(model6, accessor11.Namespace, ImportContext.Element, string.Empty, null, false, openModel, limiter); accessor11.Default = this.GetDefaultValue(model.FieldTypeDesc, model.FieldType, a); accessor11.IsNullable = false; accessor11.Form = qualified; CheckNullable(accessor11.IsNullable, desc6, accessor11.Mapping); if (!rpc) { CheckForm(accessor11.Form, ns != accessor11.Namespace); accessor11 = this.ReconcileLocalAccessor(accessor11, ns); } if (attribute5.Order != -1) { if ((attribute5.Order != order) && (order != -1)) { throw new InvalidOperationException(Res.GetString("XmlSequenceMatch", new object[] { "Order" })); } order = attribute5.Order; } scope.Add(accessor11.Name, accessor11.Namespace, accessor11); list.Add(accessor11); } } } } accessor.Elements = (ElementAccessor[]) list.ToArray(typeof(ElementAccessor)); accessor.SequenceId = order; if (rpc) { if ((accessor.TypeDesc.IsArrayLike && (accessor.Elements.Length > 0)) && !(accessor.Elements[0].Mapping is ArrayMapping)) { throw new InvalidOperationException(Res.GetString("XmlRpcLitArrayElement", new object[] { accessor.Elements[0].Name })); } if (accessor.Xmlns != null) { throw new InvalidOperationException(Res.GetString("XmlRpcLitXmlns", new object[] { accessor.Name })); } } if (accessor.ChoiceIdentifier != null) { accessor.ChoiceIdentifier.MemberIds = new string[accessor.Elements.Length]; for (int num8 = 0; num8 < accessor.Elements.Length; num8++) { bool flag2 = false; ElementAccessor accessor12 = accessor.Elements[num8]; EnumMapping mapping2 = (EnumMapping) accessor.ChoiceIdentifier.Mapping; for (int num9 = 0; num9 < mapping2.Constants.Length; num9++) { string xmlName = mapping2.Constants[num9].XmlName; if (accessor12.Any && (accessor12.Name.Length == 0)) { string str8 = (accessor12.AnyNamespaces == null) ? "##any" : accessor12.AnyNamespaces; if (!(xmlName.Substring(0, xmlName.Length - 1) == str8)) { continue; } accessor.ChoiceIdentifier.MemberIds[num8] = mapping2.Constants[num9].Name; flag2 = true; break; } int length = xmlName.LastIndexOf(':'); string str9 = (length < 0) ? mapping2.Namespace : xmlName.Substring(0, length); string str10 = (length < 0) ? xmlName : xmlName.Substring(length + 1); if ((accessor12.Name == str10) && (((accessor12.Form == XmlSchemaForm.Unqualified) && string.IsNullOrEmpty(str9)) || (accessor12.Namespace == str9))) { accessor.ChoiceIdentifier.MemberIds[num8] = mapping2.Constants[num9].Name; flag2 = true; break; } } if (!flag2) { if (accessor12.Any && (accessor12.Name.Length == 0)) { throw new InvalidOperationException(Res.GetString("XmlChoiceMissingAnyValue", new object[] { accessor.ChoiceIdentifier.Mapping.TypeDesc.FullName })); } string str11 = ((accessor12.Namespace != null) && (accessor12.Namespace.Length > 0)) ? (accessor12.Namespace + ":" + accessor12.Name) : accessor12.Name; throw new InvalidOperationException(Res.GetString("XmlChoiceMissingValue", new object[] { accessor.ChoiceIdentifier.Mapping.TypeDesc.FullName, str11, accessor12.Name, accessor12.Namespace })); } } } this.arrayNestingLevel = arrayNestingLevel; this.savedArrayItemAttributes = savedArrayItemAttributes; this.savedArrayNamespace = savedArrayNamespace; }
private void CreateArrayElementsFromAttributes(ArrayMapping arrayMapping, XmlArrayItemAttributes attributes, Type arrayElementType, string arrayElementNs, RecursionLimiter limiter) { System.Xml.Serialization.NameTable scope = new System.Xml.Serialization.NameTable(); for (int i = 0; (attributes != null) && (i < attributes.Count); i++) { XmlArrayItemAttribute attribute = attributes[i]; if (attribute.NestingLevel == this.arrayNestingLevel) { ElementAccessor accessor; Type type = (attribute.Type != null) ? attribute.Type : arrayElementType; TypeDesc typeDesc = this.typeScope.GetTypeDesc(type); accessor = new ElementAccessor { Namespace = (attribute.Namespace == null) ? arrayElementNs : attribute.Namespace, Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type), accessor.Namespace, ImportContext.Element, attribute.DataType, null, limiter), Name = (attribute.ElementName.Length == 0) ? accessor.Mapping.DefaultElementName : XmlConvert.EncodeLocalName(attribute.ElementName), IsNullable = attribute.IsNullableSpecified ? attribute.IsNullable : (typeDesc.IsNullable || typeDesc.IsOptionalValue), Form = (attribute.Form == XmlSchemaForm.None) ? XmlSchemaForm.Qualified : attribute.Form }; CheckForm(accessor.Form, arrayElementNs != accessor.Namespace); CheckNullable(accessor.IsNullable, typeDesc, accessor.Mapping); AddUniqueAccessor(scope, accessor); } } arrayMapping.Elements = (ElementAccessor[]) scope.ToArray(typeof(ElementAccessor)); }
private SpecialMapping ImportSpecialMapping(Type type, TypeDesc typeDesc, string ns, ImportContext context, RecursionLimiter limiter) { if (this.specials == null) { this.specials = new Hashtable(); } SpecialMapping mapping = (SpecialMapping) this.specials[type]; if (mapping != null) { this.CheckContext(mapping.TypeDesc, context); return mapping; } if (typeDesc.Kind == TypeKind.Serializable) { SerializableMapping mapping2 = null; object[] customAttributes = type.GetCustomAttributes(typeof(XmlSchemaProviderAttribute), false); if (customAttributes.Length > 0) { XmlSchemaProviderAttribute provider = (XmlSchemaProviderAttribute) customAttributes[0]; mapping2 = new SerializableMapping(GetMethodFromSchemaProvider(provider, type), provider.IsAny, ns); XmlQualifiedName xsiType = mapping2.XsiType; if ((xsiType != null) && !xsiType.IsEmpty) { if (this.serializables == null) { this.serializables = new System.Xml.Serialization.NameTable(); } SerializableMapping mapping3 = (SerializableMapping) this.serializables[xsiType]; if (mapping3 != null) { if (mapping3.Type == null) { mapping2 = mapping3; } else if (mapping3.Type != type) { SerializableMapping next = mapping3.Next; mapping3.Next = mapping2; mapping2.Next = next; } } else { XmlSchemaType xsdType = mapping2.XsdType; if (xsdType != null) { this.SetBase(mapping2, xsdType.DerivedFrom); } this.serializables[xsiType] = mapping2; } mapping2.TypeName = xsiType.Name; mapping2.Namespace = xsiType.Namespace; } mapping2.TypeDesc = typeDesc; mapping2.Type = type; this.IncludeTypes(type); } else { mapping2 = new SerializableMapping { TypeDesc = typeDesc, Type = type }; } mapping = mapping2; } else { mapping = new SpecialMapping { TypeDesc = typeDesc }; } this.CheckContext(typeDesc, context); this.specials.Add(type, mapping); this.typeScope.AddTypeMapping(mapping); return mapping; }
private MembersMapping ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, string ns, bool hasWrapperElement, bool rpc, bool openModel, RecursionLimiter limiter) { MembersMapping mapping = new MembersMapping { TypeDesc = this.typeScope.GetTypeDesc(typeof(object[])) }; MemberMapping[] mappingArray = new MemberMapping[xmlReflectionMembers.Length]; System.Xml.Serialization.NameTable elements = new System.Xml.Serialization.NameTable(); System.Xml.Serialization.NameTable attributes = new System.Xml.Serialization.NameTable(); TextAccessor text = null; bool isSequence = false; for (int i = 0; i < mappingArray.Length; i++) { try { MemberMapping member = this.ImportMemberMapping(xmlReflectionMembers[i], ns, xmlReflectionMembers, rpc, openModel, limiter); if (!hasWrapperElement && (member.Attribute != null)) { if (rpc) { throw new InvalidOperationException(Res.GetString("XmlRpcLitAttributeAttributes")); } throw new InvalidOperationException(Res.GetString("XmlInvalidAttributeType", new object[] { "XmlAttribute" })); } if (rpc && xmlReflectionMembers[i].IsReturnValue) { if (i > 0) { throw new InvalidOperationException(Res.GetString("XmlInvalidReturnPosition")); } member.IsReturnValue = true; } mappingArray[i] = member; isSequence |= member.IsSequence; if (!xmlReflectionMembers[i].XmlAttributes.XmlIgnore) { AddUniqueAccessor(member, elements, attributes, isSequence); } mappingArray[i] = member; if (member.Text != null) { if (text != null) { throw new InvalidOperationException(Res.GetString("XmlIllegalMultipleTextMembers")); } text = member.Text; } if (member.Xmlns != null) { if (mapping.XmlnsMember != null) { throw new InvalidOperationException(Res.GetString("XmlMultipleXmlnsMembers")); } mapping.XmlnsMember = member; } } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } throw this.CreateReflectionException(xmlReflectionMembers[i].MemberName, exception); } } if (isSequence) { throw new InvalidOperationException(Res.GetString("XmlSequenceMembers", new object[] { "Order" })); } mapping.Members = mappingArray; mapping.HasWrapperElement = hasWrapperElement; return mapping; }
private void CheckChoiceIdentifierMapping(EnumMapping choiceMapping) { System.Xml.Serialization.NameTable table = new System.Xml.Serialization.NameTable(); for (int i = 0; i < choiceMapping.Constants.Length; i++) { string xmlName = choiceMapping.Constants[i].XmlName; int length = xmlName.LastIndexOf(':'); string name = (length < 0) ? xmlName : xmlName.Substring(length + 1); string ns = (length < 0) ? "" : xmlName.Substring(0, length); if (table[name, ns] != null) { throw new InvalidOperationException(Res.GetString("XmlChoiceIdDuplicate", new object[] { choiceMapping.TypeName, xmlName })); } table.Add(name, ns, choiceMapping.Constants[i]); } }
private MemberMapping ImportChoiceGroup(XmlSchemaGroupBase group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, bool groupRepeats, ref bool needExplicitOrder, bool allowDuplicates) { System.Xml.Serialization.NameTable choiceElements = new System.Xml.Serialization.NameTable(); if (this.GatherGroupChoices(group, choiceElements, identifier, ns, ref needExplicitOrder, allowDuplicates)) { groupRepeats = true; } MemberMapping mapping = new MemberMapping { Elements = (ElementAccessor[]) choiceElements.ToArray(typeof(ElementAccessor)) }; Array.Sort(mapping.Elements, new ElementComparer()); this.AddScopeElements(elementsScope, mapping.Elements, ref needExplicitOrder, allowDuplicates); bool flag = false; bool flag2 = false; Hashtable hashtable = new Hashtable(mapping.Elements.Length); for (int i = 0; i < mapping.Elements.Length; i++) { ElementAccessor accessor = mapping.Elements[i]; string fullName = accessor.Mapping.TypeDesc.FullName; object obj2 = hashtable[fullName]; if (obj2 != null) { flag = true; ElementAccessor accessor2 = (ElementAccessor) obj2; if (!flag2 && (accessor2.IsNullable != accessor.IsNullable)) { flag2 = true; } } else { hashtable.Add(fullName, accessor); } ArrayMapping arrayMapping = accessor.Mapping as ArrayMapping; if ((arrayMapping != null) && this.IsNeedXmlSerializationAttributes(arrayMapping)) { accessor.Mapping = arrayMapping.TopLevelMapping; accessor.Mapping.ReferencedByTopLevelElement = false; accessor.Mapping.ReferencedByElement = true; } } if (flag2) { mapping.TypeDesc = base.Scope.GetTypeDesc(typeof(object)); } else { TypeDesc[] typeDescs = new TypeDesc[hashtable.Count]; IEnumerator enumerator = hashtable.Values.GetEnumerator(); for (int j = 0; j < typeDescs.Length; j++) { if (!enumerator.MoveNext()) { break; } typeDescs[j] = ((ElementAccessor) enumerator.Current).Mapping.TypeDesc; } mapping.TypeDesc = TypeDesc.FindCommonBaseTypeDesc(typeDescs); if (mapping.TypeDesc == null) { mapping.TypeDesc = base.Scope.GetTypeDesc(typeof(object)); } } if (groupRepeats) { mapping.TypeDesc = mapping.TypeDesc.CreateArrayTypeDesc(); } if (membersScope != null) { mapping.Name = membersScope.AddUnique(groupRepeats ? "Items" : "Item", mapping); if (members != null) { members.Add(mapping.Name, mapping); } } if (flag) { mapping.ChoiceIdentifier = new ChoiceIdentifierAccessor(); mapping.ChoiceIdentifier.MemberName = mapping.Name + "ElementName"; mapping.ChoiceIdentifier.Mapping = this.ImportEnumeratedChoice(mapping.Elements, ns, mapping.Name + "ChoiceType"); mapping.ChoiceIdentifier.MemberIds = new string[mapping.Elements.Length]; ConstantMapping[] constants = ((EnumMapping) mapping.ChoiceIdentifier.Mapping).Constants; for (int k = 0; k < mapping.Elements.Length; k++) { mapping.ChoiceIdentifier.MemberIds[k] = constants[k].Name; } MemberMapping mapping3 = new MemberMapping { Ignore = true, Name = mapping.ChoiceIdentifier.MemberName }; if (groupRepeats) { mapping3.TypeDesc = mapping.ChoiceIdentifier.Mapping.TypeDesc.CreateArrayTypeDesc(); } else { mapping3.TypeDesc = mapping.ChoiceIdentifier.Mapping.TypeDesc; } ElementAccessor accessor3 = new ElementAccessor { Name = mapping3.Name, Namespace = ns, Mapping = mapping.ChoiceIdentifier.Mapping }; mapping3.Elements = new ElementAccessor[] { accessor3 }; if (membersScope != null) { accessor3.Name = mapping3.Name = mapping.ChoiceIdentifier.MemberName = membersScope.AddUnique(mapping.ChoiceIdentifier.MemberName, mapping3); if (members != null) { members.Add(accessor3.Name, mapping3); } } } return mapping; }
internal void RemoveReference(XmlQualifiedName name, System.Xml.Serialization.NameTable references) { references[name] = null; }