XsdDataContractExporter.CanExport 方法

定义

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

重载

名称 说明
CanExport(ICollection<Assembly>)

获取一个值,该值指示是否可以导出一组程序集中包含的 .common language runtime (CLR) 类型集。

CanExport(ICollection<Type>)

获取一个值,该值指示是否可以导出包含在其中的 ICollection<T> .common language runtime (CLR) 类型的集。

CanExport(Type)

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

Assembly其中一个ICollection<T>包含要导出的类型的程序集。

返回

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>包含要导出的指定类型。

返回

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

适用于

CanExport(Type)

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

适用于