다음을 통해 공유


XsdDataContractImporter.CodeCompileUnit 속성

정의

생성된 CLR 형식을 저장하기 위해 사용되는 CodeCompileUnit을 가져옵니다.

public:
 property System::CodeDom::CodeCompileUnit ^ CodeCompileUnit { System::CodeDom::CodeCompileUnit ^ get(); };
public System.CodeDom.CodeCompileUnit CodeCompileUnit { get; }
member this.CodeCompileUnit : System.CodeDom.CodeCompileUnit
Public ReadOnly Property CodeCompileUnit As CodeCompileUnit

속성 값

CodeCompileUnit

생성된 CLR 형식을 저장하는 데 사용되는 CodeCompileUnit입니다.

예제

다음 예제에서는 CodeCompileUnit을 만듭니다. 그런 다음 CodeCompileUnit을 사용하여 Visual C# 및 Visual Basic 코드 파일을 만듭니다.

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();
    }
    else
    {
        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);
        sw.Close();
    }
}
Shared Sub CompileCode(ByVal ccu As CodeCompileUnit, ByVal sourceName As String) 
    Dim provider As CodeDomProvider = Nothing
    Dim sourceFile As 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" Then
        provider = New Microsoft.CSharp.CSharpCodeProvider()
    ElseIf sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) = ".VB" Then
        provider = New Microsoft.VisualBasic.VBCodeProvider()
    Else
        Console.WriteLine("Source file must have a .cs or .vb extension")
    End If
    If Not (provider Is Nothing) Then
        Dim options As New CodeGeneratorOptions()
        ' Set code formatting options to your preference. 
        options.BlankLinesBetweenMembers = True
        options.BracingStyle = "C"
        
        Dim sw As New StreamWriter(sourceName)
        provider.GenerateCodeFromCompileUnit(ccu, sw, options)
        sw.Close()
    End If

End Sub

설명

생성된 모든 코드가 저장된 XsdDataContractImporter에 액세스하려면 CodeCompileUnit를 사용하여 스키마를 가져온 후 이 속성을 호출합니다.

적용 대상

추가 정보