XsdDataContractExporter.CanExport 方法

定義

取得值,這個值表示是否能夠匯出 Common Language Runtime (CLR) 類型 (或類型集合)。

多載

CanExport(ICollection<Assembly>)

取得值,這個值表示是否能夠匯出包含在組件集合中的 Common Language Runtime (CLR) 類型集合。

CanExport(ICollection<Type>)

取得值,這個值表示是否能夠匯出包含在 ICollection<T> 中的 Common Language Runtime (CLR) 類型集合。

CanExport(Type)

取得值,這個值表示是否能夠匯出指定的 Common Language Runtime (CLR) 類型。

備註

並不是所有的 CLR 型別都能夠用在資料合約中。 如需可序列化之專案的詳細資訊,請參閱 資料合約序列化程式支援的類型

CanExport(ICollection<Assembly>)

取得值,這個值表示是否能夠匯出包含在組件集合中的 Common Language Runtime (CLR) 類型集合。

public:
 bool CanExport(System::Collections::Generic::ICollection<System::Reflection::Assembly ^> ^ assemblies);
public bool CanExport (System.Collections.Generic.ICollection<System.Reflection.Assembly> assemblies);
member this.CanExport : System.Collections.Generic.ICollection<System.Reflection.Assembly> -> bool
Public Function CanExport (assemblies As ICollection(Of Assembly)) As Boolean

參數

assemblies
ICollection<Assembly>

AssemblyICollection<T>,其中包含具有要匯出之類型的組件。

傳回

Boolean

如果能夠匯出類型,則為 true;否則為 false

適用於

CanExport(ICollection<Type>)

取得值,這個值表示是否能夠匯出包含在 ICollection<T> 中的 Common Language Runtime (CLR) 類型集合。

public:
 bool CanExport(System::Collections::Generic::ICollection<Type ^> ^ types);
public bool CanExport (System.Collections.Generic.ICollection<Type> types);
member this.CanExport : System.Collections.Generic.ICollection<Type> -> bool
Public Function CanExport (types As ICollection(Of Type)) As Boolean

參數

types
ICollection<Type>

ICollection<T>,其中包含要匯出的指定類型。

傳回

Boolean

如果能夠匯出類型,則為 true;否則為 false

適用於

CanExport(Type)

取得值,這個值表示是否能夠匯出指定的 Common Language Runtime (CLR) 類型。

public:
 bool CanExport(Type ^ type);
public bool CanExport (Type type);
member this.CanExport : Type -> bool
Public Function CanExport (type As Type) As Boolean

參數

type
Type

要匯出的 Type

傳回

Boolean

如果能夠匯出類型,則為 true;否則為 false

範例

下列程式碼範例會在呼叫 CanExport(Type) 方法之前先呼叫 Export(Type) 方法。

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);
        }
    }
}
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

適用於