Editare

Partajați prin


XsdDataContractExporter.CanExport Method

Definition

Gets a value that indicates whether a common language runtime (CLR) type (or set of types) can be exported.

Overloads

CanExport(ICollection<Assembly>)

Gets a value that indicates whether the set of .common language runtime (CLR) types contained in a set of assemblies can be exported.

CanExport(ICollection<Type>)

Gets a value that indicates whether the set of .common language runtime (CLR) types contained in a ICollection<T> can be exported.

CanExport(Type)

Gets a value that indicates whether the specified common language runtime (CLR) type can be exported.

Remarks

Not all CLR types can be used in data contracts. For more information about what can be serialized, see Types Supported by the Data Contract Serializer.

CanExport(ICollection<Assembly>)

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

Gets a value that indicates whether the set of .common language runtime (CLR) types contained in a set of assemblies can be exported.

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

Parameters

assemblies
ICollection<Assembly>

A ICollection<T> of Assembly that contains the assemblies with the types to export.

Returns

true if the types can be exported; otherwise, false.

Applies to

CanExport(ICollection<Type>)

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

Gets a value that indicates whether the set of .common language runtime (CLR) types contained in a ICollection<T> can be exported.

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

Parameters

types
ICollection<Type>

A ICollection<T> that contains the specified types to export.

Returns

true if the types can be exported; otherwise, false.

Applies to

CanExport(Type)

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

Gets a value that indicates whether the specified common language runtime (CLR) type can be exported.

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

Parameters

type
Type

The Type to export.

Returns

true if the type can be exported; otherwise, false.

Examples

The following example calls the CanExport(Type) method before calling the Export(Type) method.

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

Applies to