This documentation is archived and is not being maintained.

XsdDataContractImporter.CodeCompileUnit Property

Gets a CodeCompileUnit used for storing the CLR types generated.

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

public CodeCompileUnit CodeCompileUnit { get; }

Property Value

Type: System.CodeDom.CodeCompileUnit
A CodeCompileUnit used to store the CLR types generated.

Call this property after importing schemas using the XsdDataContractImporter to access the CodeCompileUnit in which all the generated code is stored.

The following example uses creates a CodeCompileUnit. The CodeCompileUnit is then used to create both a Visual C# and Visual Basic code file.

static void CompileCode(CodeCompileUnit ccu, string sourceName)
    CodeDomProvider provider = null;
    FileInfo sourceFile = new FileInfo(sourceName);
    // Select the code provider based on the input file extension, either C# or Visual Basic.
    if (sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) == ".CS")
        provider = new Microsoft.CSharp.CSharpCodeProvider();
    else if (sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) == ".VB")
        provider = new Microsoft.VisualBasic.VBCodeProvider();
        Console.WriteLine("Source file must have a .cs or .vb extension");
    if (provider != null)
        CodeGeneratorOptions options = new CodeGeneratorOptions();
        // Set code formatting options to your preference.
        options.BlankLinesBetweenMembers = true;
        options.BracingStyle = "C";

        StreamWriter sw = new StreamWriter(sourceName);
        provider.GenerateCodeFromCompileUnit(ccu, sw, options);

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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