ExportOptions ExportOptions ExportOptions ExportOptions Class

定義

表示 XsdDataContractExporter 可以設定的選項。Represents the options that can be set for an XsdDataContractExporter.

public ref class ExportOptions
public class ExportOptions
type ExportOptions = class
Public Class ExportOptions
繼承
ExportOptionsExportOptionsExportOptionsExportOptions

範例

下列範例會建立 ExportOptions 類別的執行個體,並將型別 (Possessions) 新增至 KnownTypes 屬性所傳回的集合。The following example creates an instance of the ExportOptions class and adds a type (Possessions) to the collection returned by the KnownTypes property.

XsdDataContractExporter 接著會匯出型別結構描述,包括加入至集合的 Possessions 型別。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;
    }
}
Imports System
Imports System.Collections
Imports System.Xml
Imports System.Runtime.Serialization
Imports System.Xml.Schema

Public Class Program
    Public Shared Sub Main() 
        Try
            ExportXSD()
        Catch exc As Exception
            Console.WriteLine("Message: {0} StackTrace:{1}", exc.Message, exc.StackTrace)
        Finally
            Console.ReadLine()
        End Try
    
    End Sub 
    
    
    Shared Sub ExportXSD() 

        Dim exporter As New XsdDataContractExporter()

        ' Use the ExportOptions to add the Possessions type to the 
        ' collection of KnownTypes. 
        Dim eOptions As New ExportOptions()
        eOptions.KnownTypes.Add(GetType(Possessions))        
        exporter.Options = eOptions

        If exporter.CanExport(GetType(Employee)) Then
            exporter.Export(GetType(Employee))
            Console.WriteLine("number of schemas: {0}", exporter.Schemas.Count)
            Console.WriteLine()
            Dim mySchemas As XmlSchemaSet = exporter.Schemas
            
            Dim XmlNameValue As XmlQualifiedName = _
               exporter.GetRootElementName(GetType(Employee))
            Dim EmployeeNameSpace As String = XmlNameValue.Namespace
            
            Dim schema As XmlSchema
            For Each schema In  mySchemas.Schemas(EmployeeNameSpace)
                schema.Write(Console.Out)
            Next schema
        End If
    
    End Sub 
    
    
    Shared Sub GetXmlElementName() 
        Dim myExporter As New XsdDataContractExporter()
        Dim xmlElementName As XmlQualifiedName = myExporter. _
            GetRootElementName(GetType(Employee))
        Console.WriteLine("Namespace: {0}", xmlElementName.Namespace)
        Console.WriteLine("Name: {0}", xmlElementName.Name)
        Console.WriteLine("IsEmpty: {0}", xmlElementName.IsEmpty)
    
    End Sub 
    
    <DataContract([Namespace] := "www.Contoso.com/Examples/")>  _
    Public Class Employee

        <DataMember()>  _
        Public EmployeeName As String
        <DataMember()>  _
        Private ID As String
        ' This member may return a Possessions type.
        <DataMember> _
        public Miscellaneous As Hashtable 

    End Class 

    <DataContract> _
    Public Class Possessions

        <DataMember> _
        Public ItemName As String
    End Class

End Class

備註

XsdDataContractExporter 可用來從型別或組件產生 XSD 結構描述。The XsdDataContractExporter is used to generate XSD schemas from a type or assembly. 您也可以使用 XsdDataContractImporter 從結構描述文件中產生 .NET Framework.NET Framework 程式碼。You can also use the XsdDataContractImporter to generate .NET Framework.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.

KnownTypes 會使用 DataContractSerializer 屬性來包含可在物件圖形中讀取的型別。The KnownTypes property is used by the DataContractSerializer to include types that can be read in an object graph. 如需資料合約和已知型別的詳細資訊,請參閱 < Data Contract Known TypesFor more information about the data contract and known types, see Data Contract Known Types.

如需有關資料合約的詳細資訊,請參閱Using Data ContractsFor more information about data contracts, see Using Data Contracts.

建構函式

ExportOptions() ExportOptions() ExportOptions() ExportOptions()

初始化 ExportOptions 類別的新執行個體。Initializes a new instance of the ExportOptions class.

屬性

DataContractSurrogate DataContractSurrogate DataContractSurrogate DataContractSurrogate

取得或設定序列化代理。Gets or sets a serialization surrogate.

KnownTypes KnownTypes KnownTypes KnownTypes

取得型別集合,這個集合可能會在序列化或還原序列化期間遇到。Gets the collection of types that may be encountered during serialization or deserialization.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱