ExportOptions 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示 XsdDataContractExporter 可以設定的選項。
public ref class ExportOptions
public class ExportOptions
type ExportOptions = class
Public Class ExportOptions
- 繼承
-
ExportOptions
範例
下列範例會建立 ExportOptions 類別的執行個體,並將型別 (Possessions
) 新增至 KnownTypes 屬性所傳回的集合。
XsdDataContractExporter 接著會匯出型別結構描述,包括加入至集合的 Possessions
型別。
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.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 結構描述。 您也可以使用 XsdDataContractImporter 從架構檔產生 .NET Framework 程式代碼。
如需匯入和匯出架構的詳細資訊,請參閱從類別匯入和匯出架構和匯出架構。
KnownTypes 會使用 DataContractSerializer 屬性來包含可在物件圖形中讀取的型別。 如需數據合約和已知型別的詳細資訊,請參閱 數據合約已知型別。
如需資料合約的詳細資訊,請參閱使用資料合約。
建構函式
ExportOptions() |
初始化 ExportOptions 類別的新執行個體。 |
屬性
DataContractSurrogate |
取得或設定序列化代理。 |
KnownTypes |
取得型別集合,這些型別可能會在序列化或還原序列化期間遇到。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |