XsdDataContractExporter.CanExport Metodo

Definizione

Ottiene un valore che indica se un tipo o un set di tipi CLR (Commom Language Runtime) può essere esportato.

Overload

CanExport(ICollection<Assembly>)

Ottiene un valore che indica se il set di tipi CLR contenuto in un set di assembly può essere esportato.

CanExport(ICollection<Type>)

Ottiene un valore che indica se il set di tipi CLR (Common Language Runtime ) contenuto in un'interfaccia ICollection<T> può essere esportato.

CanExport(Type)

Ottiene un valore che indica se il tipo CLR (Commom Language Runtime) specificato può essere esportato.

Commenti

Non tutti i tipi CLR possono essere utilizzati in contratti dati. Per altre informazioni su cosa è possibile serializzare, vedere Tipi supportati dal serializzatore di contratti dati.

CanExport(ICollection<Assembly>)

Ottiene un valore che indica se il set di tipi CLR contenuto in un set di assembly può essere esportato.

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

Parametri

assemblies
ICollection<Assembly>

Oggetto ICollection<T> di Assembly contenente gli assembly con i tipi da esportare.

Restituisce

Boolean

true se i tipi possono essere esportati. In caso contrario, false.

Si applica a

CanExport(ICollection<Type>)

Ottiene un valore che indica se il set di tipi CLR (Common Language Runtime ) contenuto in un'interfaccia ICollection<T> può essere esportato.

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

Parametri

types
ICollection<Type>

Oggetto ICollection<T> contenente i tipi specificati da esportare.

Restituisce

Boolean

true se i tipi possono essere esportati. In caso contrario, false.

Si applica a

CanExport(Type)

Ottiene un valore che indica se il tipo CLR (Commom Language Runtime) specificato può essere esportato.

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

Parametri

type
Type

Tipo Type da esportare.

Restituisce

Boolean

true se il tipo può essere esportato. In caso contrario, false.

Esempio

Nell'esempio seguente viene chiamato il metodo CanExport(Type) prima della chiamata al metodo 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

Si applica a