Export (0) Print
Expand All

ExportOptions Class

Represents the options that can be set for an XsdDataContractExporter.

System.Object
  System.Runtime.Serialization.ExportOptions

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

public class ExportOptions

The ExportOptions type exposes the following members.

  NameDescription
Public methodExportOptionsInitializes a new instance of the ExportOptions class.
Top

  NameDescription
Public propertyDataContractSurrogateGets or sets a serialization surrogate.
Public propertyKnownTypesGets the collection of types that may be encountered during serialization or deserialization.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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