XsdDataContractExporter.CanExport Méthode

Définition

Obtient une valeur qui indique si un type CLR (Common Language Runtime) peut être exporté.

Surcharges

CanExport(ICollection<Assembly>)

Obtient une valeur qui indique si l'ensemble des types CLR (Common Language Runtime) contenu dans un ensemble d'assemblys peut être exporté.

CanExport(ICollection<Type>)

Obtient une valeur qui indique si l'ensemble des types CLR (Common Language Runtime) contenu dans un ICollection<T> peut être exporté.

CanExport(Type)

Obtient une valeur qui indique si le type CLR spécifié peut être exporté.

Remarques

Les types CLR ne peuvent pas tous être utilisés dans les contrats de données. Pour plus d’informations sur ce qui peut être sérialisé, consultez Types pris en charge par le sérialiseur de contrat de données.

CanExport(ICollection<Assembly>)

Obtient une valeur qui indique si l'ensemble des types CLR (Common Language Runtime) contenu dans un ensemble d'assemblys peut être exporté.

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

Paramètres

assemblies
ICollection<Assembly>

Un ICollection<T> de Assembly qui contient les assemblys avec les types à exporter.

Retours

Boolean

true si les types peuvent être exportés ; sinon, false.

S’applique à

CanExport(ICollection<Type>)

Obtient une valeur qui indique si l'ensemble des types CLR (Common Language Runtime) contenu dans un ICollection<T> peut être exporté.

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

Paramètres

types
ICollection<Type>

ICollection<T> qui contient les types spécifiés à exporter.

Retours

Boolean

true si les types peuvent être exportés ; sinon, false.

S’applique à

CanExport(Type)

Obtient une valeur qui indique si le type CLR spécifié peut être exporté.

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

Paramètres

type
Type

Type à exporter.

Retours

Boolean

true si le type peut être exporté ; sinon, false.

Exemples

L'exemple suivant appelle la méthode CanExport(Type) avant d'appeler la méthode 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

S’applique à