Export (0) Print
Expand All

ImportOptions Class

Represents the options that can be set on an XsdDataContractImporter.

System.Object
  System.Runtime.Serialization.ImportOptions

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

public class ImportOptions

The ImportOptions type exposes the following members.

  NameDescription
Public methodImportOptionsInitializes a new instance of the ImportOptions class.
Top

  NameDescription
Public propertyCodeProviderGets or sets a CodeDomProvider instance that provides the means to check whether particular options for a target language are supported.
Public propertyDataContractSurrogateGets or sets a data contract surrogate that can be used to modify the code generated during an import operation.
Public propertyEnableDataBindingGets or sets a value that specifies whether types in generated code should implement the INotifyPropertyChanged interface.
Public propertyGenerateInternalGets or sets a value that specifies whether generated code will be marked internal or public.
Public propertyGenerateSerializableGets or sets a value that specifies whether generated data contract classes will be marked with the SerializableAttribute attribute in addition to the DataContractAttribute attribute.
Public propertyImportXmlTypeGets or sets a value that determines whether all XML schema types, even those that do not conform to a data contract schema, will be imported.
Public propertyNamespacesGets a dictionary that contains the mapping of data contract namespaces to the CLR namespaces that must be used to generate code during an import operation.
Public propertyReferencedCollectionTypesGets a collection of types that represents data contract collections that should be referenced when generating code for collections, such as lists or dictionaries of items.
Public propertyReferencedTypesGets a IList<T> containing types referenced in generated code.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The XsdDataContractImporter is used to generate code from XML schema using the .NET Framework CodeDOM. To generate an XML schema from an assembly, use the XsdDataContractExporter.

For more information about importing and exporting schemas, see Schema Import and Export and Importing Schema to Generate Classes.

The following example creates an instance of the ImportOptions class and sets the EnableDataBinding and GenerateInternal properties.

static CodeCompileUnit Import(XmlSchemaSet schemas)
{

    XsdDataContractImporter imp = new XsdDataContractImporter();

    // The EnableDataBinding option adds a RaisePropertyChanged method to 
    // the generated code. The GenerateInternal causes code access to be 
    // set to internal.
    ImportOptions iOptions = new ImportOptions();
    iOptions.EnableDataBinding = true;
    iOptions.GenerateInternal = true;
    imp.Options = iOptions;


    if (imp.CanImport(schemas))
    {
        imp.Import(schemas);
        return imp.CodeCompileUnit;
    }
    else 
        return null;
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft