private void ExportXmlDataContract(XmlDataContract dataContract)
        {
            Type clrType = dataContract.UnderlyingType;

            if (!IsSpecialXmlType(clrType, out XmlQualifiedName typeQName, out XmlSchemaType xsdType, out bool 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");
                }

                if (SchemaHelper.GetSchemaElement(Schemas,
                                                  new XmlQualifiedName(dataContract.TopLevelElementName.Value, dataContract.TopLevelElementNamespace.Value),
                                                  out XmlSchema 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 Compat.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
                        );
                }
            }
        }
        private void SetElementType(XmlSchemaElement element, DataContract dataContract, XmlSchema schema)
        {
            XmlDataContract xmlDataContract = dataContract as XmlDataContract;

            if (xmlDataContract != null && xmlDataContract.IsAnonymous)
            {
                element.SchemaType = xmlDataContract.XsdType;
            }
            else
            {
                element.SchemaTypeName = dataContract.StableName;

                if (element.SchemaTypeName.Namespace.Equals(Globals.SerializationNamespace))
                {
                    schema.Namespaces.Add(Globals.SerPrefixForSchema, Globals.SerializationNamespace);
                }

                SchemaHelper.AddSchemaImport(dataContract.StableName.Namespace, schema);
            }
        }