CodeGenerationOptions Enum
Specifies options for generating code from metadata.
Syntax
public enum CodeGenerationOptions
Remarks
The CodeGenerationOptions enumeration provides a set of flags that can be combined to control the code generation process. These options are typically used when generating classes from metadata, such as XML schemas or other serialization formats, to customize the resulting code's behavior and structure.
For example, you can specify whether to generate data contracts for types that are not marked with the DataContractAttribute, or whether to include default values in the generated code.
Members
| Name | Description |
|---|---|
None |
No options are specified. This is the default value. |
GenerateInternal |
Generates internal types. By default, only public types are generated. |
GenerateExternalizable |
Generates types that implement the IExtensibleXmlSerializable interface. |
GenerateAsLazy |
Generates types with lazy initialization. This can improve performance by deferring the creation of objects until they are actually needed. |
GenerateComplexTypesAsXsdSchema |
Generates complex types as XSD schemas. This is useful when you need to represent complex data structures in a schema format. |
GenerateOldXmlAttributeStyle |
Generates XML attributes using the older style. |
GenerateOptionalContracts |
Generates optional contracts for members. This allows for more flexibility in serialization. |
Example Usage
The following example demonstrates how to use the CodeGenerationOptions.GenerateInternal flag when creating a DataContractSerializer.
// Assuming MyDataContract is a class marked with DataContractAttribute using System.Runtime.Serialization; DataContractSerializer serializer = new DataContractSerializer( typeof(MyDataContract), new DataContractSerializerSettings { CodeGeneratorOptions = CodeGenerationOptions.GenerateInternal }); // Now, the serializer can handle internal types within MyDataContract // ... serialization/deserialization logic ...
Requirements
Namespace: System.Runtime.Serialization
Assembly: System.Runtime.Serialization.dll