GetSchemaElement() static private method

static private GetSchemaElement ( SchemaObjectDictionary schemaInfo, XmlQualifiedName elementName ) : XmlSchemaElement
schemaInfo SchemaObjectDictionary
elementName System.Xml.XmlQualifiedName
return System.Xml.Schema.XmlSchemaElement
Beispiel #1
0
        private void ExportXmlDataContract(XmlDataContract dataContract)
        {
            XmlQualifiedName typeQName;
            bool             hasRoot;
            XmlSchemaType    xsdType;

            Type clrType = dataContract.UnderlyingType;

            if (!IsSpecialXmlType(clrType, out typeQName, out xsdType, out hasRoot))
            {
                if (!InvokeSchemaProviderMethod(clrType, _schemas, out typeQName, out xsdType, out hasRoot))
                {
                    InvokeGetSchemaMethod(clrType, _schemas, typeQName);
                }
            }

            if (hasRoot)
            {
                if (!(typeQName.Equals(dataContract.StableName)))
                {
                    Fx.Assert("XML data contract type name does not match schema name");
                }

                XmlSchema schema;
                if (SchemaHelper.GetSchemaElement(Schemas,
                                                  new XmlQualifiedName(dataContract.TopLevelElementName.Value, dataContract.TopLevelElementNamespace.Value),
                                                  out schema) == null)
                {
                    XmlSchemaElement topLevelElement = ExportTopLevelElement(dataContract, schema);
                    topLevelElement.IsNillable = dataContract.IsTopLevelElementNullable;
                    ReprocessAll(_schemas);
                }

                XmlSchemaType anonymousType = xsdType;
                xsdType = SchemaHelper.GetSchemaType(_schemas, typeQName, out schema);
                if (anonymousType == null && xsdType == null && typeQName.Namespace != XmlSchema.Namespace)
                {
                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingSchemaType, typeQName, DataContract.GetClrTypeFullName(clrType))));
                }
                if (xsdType != null)
                {
                    xsdType.Annotation = GetSchemaAnnotation(
                        ExportSurrogateData(dataContract),
                        dataContract.IsValueType ?
                        GetAnnotationMarkup(IsValueTypeName, XmlConvert.ToString(dataContract.IsValueType), schema) :
                        null
                        );
                }
            }
        }