XmlSchemaAttribute GetSchemaAttribute(XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo, bool isTypeMember) { XmlSchemaAttribute sat = new XmlSchemaAttribute(); if (attinfo.DefaultValue != System.DBNull.Value) { sat.DefaultValue = XmlCustomFormatter.ToXmlString(attinfo.TypeData, attinfo.DefaultValue); } 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); }
private XmlSchemaAttribute GetSchemaAttribute(XmlSchema currentSchema, XmlTypeMapMemberAttribute attinfo, bool isTypeMember) { XmlSchemaAttribute xmlSchemaAttribute = new XmlSchemaAttribute(); if (attinfo.DefaultValue != DBNull.Value) { xmlSchemaAttribute.DefaultValue = this.ExportDefaultValue(attinfo.TypeData, attinfo.MappedType, attinfo.DefaultValue); } else if (!attinfo.IsOptionalValueType && attinfo.TypeData.IsValueType) { xmlSchemaAttribute.Use = XmlSchemaUse.Required; } this.ImportNamespace(currentSchema, attinfo.Namespace); XmlSchema xmlSchema; if (attinfo.Namespace.Length == 0 && attinfo.Form != XmlSchemaForm.Qualified) { xmlSchema = currentSchema; } else { xmlSchema = this.GetSchema(attinfo.Namespace); } if (currentSchema != xmlSchema && !this.encodedFormat) { xmlSchemaAttribute.RefName = new XmlQualifiedName(attinfo.AttributeName, attinfo.Namespace); foreach (XmlSchemaObject xmlSchemaObject in xmlSchema.Items) { if (xmlSchemaObject is XmlSchemaAttribute && ((XmlSchemaAttribute)xmlSchemaObject).Name == attinfo.AttributeName) { return(xmlSchemaAttribute); } } xmlSchema.Items.Add(this.GetSchemaAttribute(xmlSchema, attinfo, false)); return(xmlSchemaAttribute); } xmlSchemaAttribute.Name = attinfo.AttributeName; if (isTypeMember) { xmlSchemaAttribute.Form = attinfo.Form; } if (attinfo.TypeData.SchemaType == SchemaTypes.Enum) { this.ImportNamespace(currentSchema, attinfo.DataTypeNamespace); this.ExportEnumSchema(attinfo.MappedType); xmlSchemaAttribute.SchemaTypeName = new XmlQualifiedName(attinfo.TypeData.XmlType, attinfo.DataTypeNamespace); } else if (attinfo.TypeData.SchemaType == SchemaTypes.Array && TypeTranslator.IsPrimitive(attinfo.TypeData.ListItemType)) { xmlSchemaAttribute.SchemaType = this.GetSchemaSimpleListType(attinfo.TypeData); } else { xmlSchemaAttribute.SchemaTypeName = new XmlQualifiedName(attinfo.TypeData.XmlType, attinfo.DataTypeNamespace); } return(xmlSchemaAttribute); }