Share via


XsdDataContractExporter.CanExport 方法

定义

获取一个值,该值指示公共语言运行库 (CLR) 类型(或类型集)是否可以导出。

重载

CanExport(ICollection<Assembly>)

获取一个值,该值指示一组程序集中包含的公共语言运行库 (CLR) 类型集是否可以导出。

CanExport(ICollection<Type>)

获取一个值,该值指示 ICollection<T> 中包含的公共语言运行时 (CLR) 类型集是否可以导出。

CanExport(Type)

获取一个值,该值指示指定的公共语言运行时 (CLR) 类型是否可以导出。

注解

并非所有 CLR 类型都可在数据协定中使用。 有关可序列化的内容的详细信息,请参阅 数据协定序列化程序支持的类型

CanExport(ICollection<Assembly>)

Source:
XsdDataContractExporter.cs
Source:
XsdDataContractExporter.cs
Source:
XsdDataContractExporter.cs

获取一个值,该值指示一组程序集中包含的公共语言运行库 (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>

一个由 ICollection<T> 组成的 Assembly,其中包含具有要导出的类型的程序集。

返回

如果类型可以导出,则为 true;否则为 false

适用于

CanExport(ICollection<Type>)

Source:
XsdDataContractExporter.cs
Source:
XsdDataContractExporter.cs
Source:
XsdDataContractExporter.cs

获取一个值,该值指示 ICollection<T> 中包含的公共语言运行时 (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>,它包含要导出的指定类型。

返回

如果类型可以导出,则为 true;否则为 false

适用于

CanExport(Type)

Source:
XsdDataContractExporter.cs
Source:
XsdDataContractExporter.cs
Source:
XsdDataContractExporter.cs

获取一个值,该值指示指定的公共语言运行时 (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

返回

如果类型可以导出,则为 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

适用于