XsdDataContractExporter.CanExport Method (Type)

 

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

Namespace:   System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

public bool CanExport(
	Type type
)

Parameters

type
Type: System.Type

The Type to export.

Return Value

Type: System.Boolean

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

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);
        }
    }
}

.NET Framework
Available since 3.0
Return to top
Show: