private XmlSchemaParticle GetSchemaElement(XmlSchema currentSchema, XmlTypeMapElementInfo einfo, object defaultValue, bool isTypeMember, XmlSchemaExporter.XmlSchemaObjectContainer container) { if (einfo.IsTextElement) { return(null); } if (einfo.IsUnnamedAnyElement) { XmlSchemaAny xmlSchemaAny = new XmlSchemaAny(); xmlSchemaAny.MinOccurs = 0m; xmlSchemaAny.MaxOccurs = 1m; if (container != null) { container.Items.Add(xmlSchemaAny); } return(xmlSchemaAny); } XmlSchemaElement xmlSchemaElement = new XmlSchemaElement(); xmlSchemaElement.IsNillable = einfo.IsNullable; if (container != null) { container.Items.Add(xmlSchemaElement); } if (isTypeMember) { xmlSchemaElement.MaxOccurs = 1m; xmlSchemaElement.MinOccurs = ((!einfo.IsNullable) ? 0 : 1); if ((defaultValue == DBNull.Value && einfo.TypeData.IsValueType && einfo.Member != null && !einfo.Member.IsOptionalValueType) || this.encodedFormat) { xmlSchemaElement.MinOccurs = 1m; } } XmlSchema xmlSchema = null; if (!this.encodedFormat) { xmlSchema = this.GetSchema(einfo.Namespace); this.ImportNamespace(currentSchema, einfo.Namespace); } if (currentSchema != xmlSchema && !this.encodedFormat && isTypeMember) { xmlSchemaElement.RefName = new XmlQualifiedName(einfo.ElementName, einfo.Namespace); foreach (XmlSchemaObject xmlSchemaObject in xmlSchema.Items) { if (xmlSchemaObject is XmlSchemaElement && ((XmlSchemaElement)xmlSchemaObject).Name == einfo.ElementName) { return(xmlSchemaElement); } } this.GetSchemaElement(xmlSchema, einfo, defaultValue, false, new XmlSchemaExporter.XmlSchemaObjectContainer(xmlSchema)); return(xmlSchemaElement); } if (isTypeMember) { xmlSchemaElement.IsNillable = einfo.IsNullable; } xmlSchemaElement.Name = einfo.ElementName; if (defaultValue != DBNull.Value) { xmlSchemaElement.DefaultValue = this.ExportDefaultValue(einfo.TypeData, einfo.MappedType, defaultValue); } if (einfo.Form != XmlSchemaForm.Qualified) { xmlSchemaElement.Form = einfo.Form; } switch (einfo.TypeData.SchemaType) { case SchemaTypes.Primitive: xmlSchemaElement.SchemaTypeName = new XmlQualifiedName(einfo.TypeData.XmlType, einfo.DataTypeNamespace); if (!einfo.TypeData.IsXsdType) { this.ImportNamespace(currentSchema, einfo.MappedType.XmlTypeNamespace); this.ExportDerivedSchema(einfo.MappedType); } break; case SchemaTypes.Enum: xmlSchemaElement.SchemaTypeName = new XmlQualifiedName(einfo.MappedType.XmlType, einfo.MappedType.XmlTypeNamespace); this.ImportNamespace(currentSchema, einfo.MappedType.XmlTypeNamespace); this.ExportEnumSchema(einfo.MappedType); break; case SchemaTypes.Array: { XmlQualifiedName xmlQualifiedName = this.ExportArraySchema(einfo.MappedType, currentSchema.TargetNamespace); xmlSchemaElement.SchemaTypeName = xmlQualifiedName; this.ImportNamespace(currentSchema, xmlQualifiedName.Namespace); break; } case SchemaTypes.Class: if (einfo.MappedType.TypeData.Type != typeof(object)) { xmlSchemaElement.SchemaTypeName = new XmlQualifiedName(einfo.MappedType.XmlType, einfo.MappedType.XmlTypeNamespace); this.ImportNamespace(currentSchema, einfo.MappedType.XmlTypeNamespace); } else if (this.encodedFormat) { xmlSchemaElement.SchemaTypeName = new XmlQualifiedName(einfo.MappedType.XmlType, einfo.MappedType.XmlTypeNamespace); } this.ExportClassSchema(einfo.MappedType); break; case SchemaTypes.XmlSerializable: this.SetSchemaXmlSerializableType(einfo.MappedType as XmlSerializableMapping, xmlSchemaElement); this.ExportXmlSerializableSchema(currentSchema, einfo.MappedType as XmlSerializableMapping); break; case SchemaTypes.XmlNode: xmlSchemaElement.SchemaType = this.GetSchemaXmlNodeType(); break; } return(xmlSchemaElement); }
/// <summary>Adds an element declaration to the applicable <see cref="T:System.Xml.Schema.XmlSchema" /> for each of the element parts of a literal SOAP message definition, and specifies whether enclosing elements are included.</summary> /// <param name="xmlMembersMapping">The internal mapping between a .NET Framework type and an XML schema element.</param> /// <param name="exportEnclosingType">true if the schema elements that enclose the schema are to be included; otherwise, false.</param> public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType) { ClassMap classMap = (ClassMap)xmlMembersMapping.ObjectMap; if (xmlMembersMapping.HasWrapperElement && exportEnclosingType) { XmlSchema schema = this.GetSchema(xmlMembersMapping.Namespace); XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType(); XmlSchemaSequence particle; XmlSchemaAnyAttribute anyAttribute; this.ExportMembersMapSchema(schema, classMap, null, xmlSchemaComplexType.Attributes, out particle, out anyAttribute); xmlSchemaComplexType.Particle = particle; xmlSchemaComplexType.AnyAttribute = anyAttribute; if (this.encodedFormat) { xmlSchemaComplexType.Name = xmlMembersMapping.ElementName; schema.Items.Add(xmlSchemaComplexType); } else { XmlSchemaElement xmlSchemaElement = new XmlSchemaElement(); xmlSchemaElement.Name = xmlMembersMapping.ElementName; xmlSchemaElement.SchemaType = xmlSchemaComplexType; schema.Items.Add(xmlSchemaElement); } } else { ICollection elementMembers = classMap.ElementMembers; if (elementMembers != null) { foreach (object obj in elementMembers) { XmlTypeMapMemberElement xmlTypeMapMemberElement = (XmlTypeMapMemberElement)obj; if (xmlTypeMapMemberElement is XmlTypeMapMemberAnyElement && xmlTypeMapMemberElement.TypeData.IsListType) { XmlSchema schema2 = this.GetSchema(xmlMembersMapping.Namespace); XmlSchemaParticle schemaArrayElement = this.GetSchemaArrayElement(schema2, xmlTypeMapMemberElement.ElementInfo); if (schemaArrayElement is XmlSchemaAny) { XmlSchemaComplexType xmlSchemaComplexType2 = this.FindComplexType(schema2.Items, "any"); if (xmlSchemaComplexType2 != null) { continue; } xmlSchemaComplexType2 = new XmlSchemaComplexType(); xmlSchemaComplexType2.Name = "any"; xmlSchemaComplexType2.IsMixed = true; XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence(); xmlSchemaComplexType2.Particle = xmlSchemaSequence; xmlSchemaSequence.Items.Add(schemaArrayElement); schema2.Items.Add(xmlSchemaComplexType2); continue; } } XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)xmlTypeMapMemberElement.ElementInfo[0]; XmlSchema schema3; if (this.encodedFormat) { schema3 = this.GetSchema(xmlMembersMapping.Namespace); this.ImportNamespace(schema3, "http://schemas.xmlsoap.org/soap/encoding/"); } else { schema3 = this.GetSchema(xmlTypeMapElementInfo.Namespace); } XmlSchemaElement xmlSchemaElement2 = this.FindElement(schema3.Items, xmlTypeMapElementInfo.ElementName); XmlSchemaExporter.XmlSchemaObjectContainer container = null; if (!this.encodedFormat) { container = new XmlSchemaExporter.XmlSchemaObjectContainer(schema3); } Type type = xmlTypeMapMemberElement.GetType(); if (xmlTypeMapMemberElement is XmlTypeMapMemberFlatList) { throw new InvalidOperationException("Unwrapped arrays not supported as parameters"); } XmlSchemaElement xmlSchemaElement3; if (type == typeof(XmlTypeMapMemberElement)) { xmlSchemaElement3 = (XmlSchemaElement)this.GetSchemaElement(schema3, xmlTypeMapElementInfo, xmlTypeMapMemberElement.DefaultValue, false, container); } else { xmlSchemaElement3 = (XmlSchemaElement)this.GetSchemaElement(schema3, xmlTypeMapElementInfo, false, container); } if (xmlSchemaElement2 != null) { if (!xmlSchemaElement2.SchemaTypeName.Equals(xmlSchemaElement3.SchemaTypeName)) { string text = "The XML element named '" + xmlTypeMapElementInfo.ElementName + "' "; string text2 = text; text = string.Concat(new string[] { text2, "from namespace '", schema3.TargetNamespace, "' references distinct types ", xmlSchemaElement3.SchemaTypeName.Name, " and ", xmlSchemaElement2.SchemaTypeName.Name, ". " }); text += "Use XML attributes to specify another XML name or namespace for the element or types."; throw new InvalidOperationException(text); } schema3.Items.Remove(xmlSchemaElement3); } } } } this.CompileSchemas(); }
private XmlSchemaParticle GetSchemaElement(XmlSchema currentSchema, XmlTypeMapElementInfo einfo, bool isTypeMember, XmlSchemaExporter.XmlSchemaObjectContainer container) { return(this.GetSchemaElement(currentSchema, einfo, DBNull.Value, isTypeMember, container)); }