ExportOptions.KnownTypes Property

Definition

Gets the collection of types that may be encountered during serialization or deserialization.

C#
public System.Collections.ObjectModel.Collection<Type> KnownTypes { get; }

Property Value

A KnownTypes collection that contains types that may be encountered during serialization or deserialization. XML schema representations are exported for all the types specified in this collection by the XsdDataContractExporter.

Examples

The following example creates an instance of the ExportOptions class and adds a type to the collection returned by the KnownTypes property.

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

Remarks

The KnownTypes property is used by the DataContractSerializer to include types that can be read in an object graph (set using the DataContractSerializer.KnownTypes property).

For more information about the data contract and known types, see Data Contract Known Types.

Applies to

Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also