ExportOptions Class
TOC
Collapse the table of content
Expand the table of content

ExportOptions Class

 

Represents the options that can be set for an XsdDataContractExporter.

Namespace:   System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

System.Object
  System.Runtime.Serialization.ExportOptions

public class ExportOptions

NameDescription
System_CAPS_pubmethodExportOptions()

Initializes a new instance of the ExportOptions class.

NameDescription
System_CAPS_pubpropertyDataContractSurrogate

Gets or sets a serialization surrogate.

System_CAPS_pubpropertyKnownTypes

Gets the collection of types that may be encountered during serialization or deserialization.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

The XsdDataContractExporter is used to generate XSD schemas from a type or assembly. You can also use the XsdDataContractImporter to generate .NET Framework code from a schema document.

For more information about importing and exporting schemas, see Schema Import and Export and Exporting Schemas from Classes.

The KnownTypes property is used by the DataContractSerializer to include types that can be read in an object graph. For more information about the data contract and known types, see Data Contract Known Types.

For more information about data contracts, see Using Data Contracts.

The following example creates an instance of the ExportOptions class and adds a type (Possessions) to the collection returned by the KnownTypes property.

The XsdDataContractExporter then exports the schemas of the types, including the Possessions type added to the collection.

using System;
using System.Xml;
using System.Runtime.Serialization;
using System.Xml.Schema;

public class Program
{
    public static void Main()
    {
        try
        {
            ExportXSD();
        }
        catch (Exception exc)
        {
            Console.WriteLine("Message: {0} StackTrace:{1}", exc.Message, exc.StackTrace);
        }
        finally
        {
            Console.ReadLine();
        }
    }

    static void ExportXSD()
    {
        XsdDataContractExporter exporter = new XsdDataContractExporter();
        if (exporter.CanExport(typeof(Employee)))
        {
            exporter.Export(typeof(Employee));
            Console.WriteLine("number of schemas: {0}", exporter.Schemas.Count);
            Console.WriteLine();
            XmlSchemaSet mySchemas = exporter.Schemas;

            XmlQualifiedName XmlNameValue = exporter.GetRootElementName(typeof(Employee));
            string EmployeeNameSpace = XmlNameValue.Namespace;

            foreach (XmlSchema schema in mySchemas.Schemas(EmployeeNameSpace))
            {
                schema.Write(Console.Out);
            }
        }
    }

    static void GetXmlElementName()
    {
        XsdDataContractExporter myExporter = new XsdDataContractExporter();
        XmlQualifiedName xmlElementName =myExporter.GetRootElementName(typeof(Employee));
        Console.WriteLine("Namespace: {0}", xmlElementName.Namespace);
        Console.WriteLine("Name: {0}", xmlElementName.Name);
        Console.WriteLine("IsEmpty: {0}", xmlElementName.IsEmpty);
    }

    [DataContract(Namespace = "www.Contoso.com/Examples/")]
    public class Employee
    {
        [DataMember]
        public string EmployeeName;
        [DataMember]
        private string ID;
    }
}

.NET Framework
Available since 3.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft