System.Runtime.Serialization.SchemaHelper.GetSchemaType C# (CSharp) Метод

GetSchemaType() статический приватный Метод

static private GetSchemaType ( XmlSchemaSet schemas, XmlQualifiedName typeQName, XmlSchema &outSchema ) : XmlSchemaType
schemas System.Xml.Schema.XmlSchemaSet
typeQName System.Xml.XmlQualifiedName
outSchema System.Xml.Schema.XmlSchema
Результат System.Xml.Schema.XmlSchemaType
        internal static XmlSchemaType GetSchemaType(XmlSchemaSet schemas, XmlQualifiedName typeQName, out XmlSchema outSchema)
        {
            outSchema = null;
            ICollection currentSchemas = schemas.Schemas();
            string ns = typeQName.Namespace;
            foreach (XmlSchema schema in currentSchemas)
            {
                if (NamespacesEqual(ns, schema.TargetNamespace))
                {
                    outSchema = schema;
                    foreach (XmlSchemaObject schemaObj in schema.Items)
                    {
                        XmlSchemaType schemaType = schemaObj as XmlSchemaType;
                        if (schemaType != null && schemaType.Name == typeQName.Name)
                        {
                            return schemaType;
                        }
                    }
                }
            }
            return null;
        }

Same methods

SchemaHelper::GetSchemaType ( SchemaObjectDictionary schemaInfo, XmlQualifiedName typeName ) : XmlSchemaType

Usage Example

Пример #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
                        );
                }
            }
        }