CodeCompileUnit 클래스

정의

CodeDOM 프로그램 그래프에 대한 컨테이너를 제공합니다.

public ref class CodeCompileUnit : System::CodeDom::CodeObject
public class CodeCompileUnit : System.CodeDom.CodeObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeCompileUnit : System.CodeDom.CodeObject
type CodeCompileUnit = class
    inherit CodeObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeCompileUnit = class
    inherit CodeObject
Public Class CodeCompileUnit
Inherits CodeObject
상속
CodeCompileUnit
파생
특성

예제

다음 코드 예제에서는 CodeCompileUnit 간단한 "헬로 월드" 프로그램의 프로그램 구조를 모델링하는 를 생성합니다. 이 코드 예제는 이 모델에서 코드를 생성하고 클래스에 대해 제공되는 더 큰 예제의 CodeDomProvider 일부입니다.

// Build a Hello World program graph using 
// System::CodeDom types.
static CodeCompileUnit^ BuildHelloWorldGraph()
{
    // Create a new CodeCompileUnit to contain 
    // the program graph.
    CodeCompileUnit^ compileUnit = gcnew CodeCompileUnit;

    // Declare a new namespace called Samples.
    CodeNamespace^ samples = gcnew CodeNamespace( "Samples" );

    // Add the new namespace to the compile unit.
    compileUnit->Namespaces->Add( samples );

    // Add the new namespace import for the System namespace.
    samples->Imports->Add( gcnew CodeNamespaceImport( "System" ) );

    // Declare a new type called Class1.
    CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration( "Class1" );

    // Add the new type to the namespace's type collection.
    samples->Types->Add( class1 );

    // Declare a new code entry point method.
    CodeEntryPointMethod^ start = gcnew CodeEntryPointMethod;

    // Create a type reference for the System::Console class.
    CodeTypeReferenceExpression^ csSystemConsoleType = gcnew CodeTypeReferenceExpression( "System.Console" );

    // Build a Console::WriteLine statement.
    CodeMethodInvokeExpression^ cs1 = gcnew CodeMethodInvokeExpression( csSystemConsoleType,"WriteLine", gcnew CodePrimitiveExpression("Hello World!") );

    // Add the WriteLine call to the statement collection.
    start->Statements->Add( cs1 );

    // Build another Console::WriteLine statement.
    CodeMethodInvokeExpression^ cs2 = gcnew CodeMethodInvokeExpression( csSystemConsoleType,"WriteLine", gcnew CodePrimitiveExpression( "Press the Enter key to continue." ) );

    // Add the WriteLine call to the statement collection.
    start->Statements->Add( cs2 );

    // Build a call to System::Console::ReadLine.
    CodeMethodReferenceExpression^ csReadLine = gcnew CodeMethodReferenceExpression( csSystemConsoleType, "ReadLine" );
    CodeMethodInvokeExpression^ cs3 = gcnew CodeMethodInvokeExpression( csReadLine, gcnew array<CodeExpression^>(0) );

    // Add the ReadLine statement.
    start->Statements->Add( cs3 );

    // Add the code entry point method to
    // the Members collection of the type.
    class1->Members->Add( start );
    return compileUnit;
}
// Build a Hello World program graph using
// System.CodeDom types.
public static CodeCompileUnit BuildHelloWorldGraph()
{
    // Create a new CodeCompileUnit to contain
    // the program graph.
    CodeCompileUnit compileUnit = new CodeCompileUnit();

    // Declare a new namespace called Samples.
    CodeNamespace samples = new CodeNamespace("Samples");
    // Add the new namespace to the compile unit.
    compileUnit.Namespaces.Add(samples);

    // Add the new namespace import for the System namespace.
    samples.Imports.Add(new CodeNamespaceImport("System"));

    // Declare a new type called Class1.
    CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");
    // Add the new type to the namespace type collection.
    samples.Types.Add(class1);

    // Declare a new code entry point method.
    CodeEntryPointMethod start = new CodeEntryPointMethod();

    // Create a type reference for the System.Console class.
    CodeTypeReferenceExpression csSystemConsoleType = new CodeTypeReferenceExpression("System.Console");

    // Build a Console.WriteLine statement.
    CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
        csSystemConsoleType, "WriteLine",
        new CodePrimitiveExpression("Hello World!"));

    // Add the WriteLine call to the statement collection.
    start.Statements.Add(cs1);

    // Build another Console.WriteLine statement.
    CodeMethodInvokeExpression cs2 = new CodeMethodInvokeExpression(
        csSystemConsoleType, "WriteLine",
        new CodePrimitiveExpression("Press the Enter key to continue."));

    // Add the WriteLine call to the statement collection.
    start.Statements.Add(cs2);

    // Build a call to System.Console.ReadLine.
    CodeMethodInvokeExpression csReadLine = new CodeMethodInvokeExpression(
        csSystemConsoleType, "ReadLine");

    // Add the ReadLine statement.
    start.Statements.Add(csReadLine);

    // Add the code entry point method to
    // the Members collection of the type.
    class1.Members.Add(start);

    return compileUnit;
}
' Build a Hello World program graph using 
' System.CodeDom types.
Public Shared Function BuildHelloWorldGraph() As CodeCompileUnit

    ' Create a new CodeCompileUnit to contain 
    ' the program graph.
    Dim compileUnit As New CodeCompileUnit()

    ' Declare a new namespace called Samples.
    Dim samples As New CodeNamespace("Samples")

    ' Add the new namespace to the compile unit.
    compileUnit.Namespaces.Add(samples)

    ' Add the new namespace import for the System namespace.
    samples.Imports.Add(New CodeNamespaceImport("System"))

    ' Declare a new type called Class1.
    Dim class1 As New CodeTypeDeclaration("Class1")

    ' Add the new type to the namespace type collection.
    samples.Types.Add(class1)

    ' Declare a new code entry point method.
    Dim start As New CodeEntryPointMethod()

    ' Create a type reference for the System.Console class.
    Dim csSystemConsoleType As New CodeTypeReferenceExpression( _
        "System.Console")

    ' Build a Console.WriteLine statement.
    Dim cs1 As New CodeMethodInvokeExpression( _
        csSystemConsoleType, "WriteLine", _
        New CodePrimitiveExpression("Hello World!"))

    ' Add the WriteLine call to the statement collection.
    start.Statements.Add(cs1)

    ' Build another Console.WriteLine statement.
    Dim cs2 As New CodeMethodInvokeExpression( _
        csSystemConsoleType, "WriteLine", _
        New CodePrimitiveExpression("Press the Enter key to continue."))

    ' Add the WriteLine call to the statement collection.
    start.Statements.Add(cs2)

    ' Build a call to System.Console.ReadLine.
    Dim csReadLine As New CodeMethodInvokeExpression( _
        csSystemConsoleType, "ReadLine")

    ' Add the ReadLine statement.
    start.Statements.Add(csReadLine)

    ' Add the code entry point method to
    ' the Members collection of the type.
    class1.Members.Add(start)

    Return compileUnit
End Function

설명

CodeCompileUnit 는 CodeDOM 프로그램 그래프에 대한 컨테이너를 제공합니다.

CodeCompileUnit 에는 CodeDOM 소스 코드 그래프가 포함된 개체와 프로젝트에서 참조하는 어셈블리 컬렉션 및 프로젝트 어셈블리에 대한 특성 컬렉션을 저장할 CodeNamespace 수 있는 컬렉션이 포함되어 있습니다.

CodeCompileUnit 다른 매개 변수와 함께 구현의 ICodeGenerator 메서드에 전달 GenerateCodeFromCompileUnit 하여 컴파일 단위에 포함된 프로그램 그래프를 기반으로 코드를 생성할 수 있습니다.

참고

일부 언어는 컴파일 단위에 단일 클래스를 포함하는 단일 네임스페이스만 지원합니다.

생성자

CodeCompileUnit()

CodeCompileUnit 클래스의 새 인스턴스를 초기화합니다.

속성

AssemblyCustomAttributes

생성된 어셈블리에 대한 사용자 지정 특성 컬렉션을 가져옵니다.

EndDirectives

종료 지시문이 들어 있는 CodeDirectiveCollection 개체를 가져옵니다.

Namespaces

네임스페이스의 컬렉션을 가져옵니다.

ReferencedAssemblies

참조된 어셈블리를 가져옵니다.

StartDirectives

시작 지시문이 들어 있는 CodeDirectiveCollection 개체를 가져옵니다.

UserData

현재 개체에 대해 사용자 정의 가능한 데이터를 가져옵니다.

(다음에서 상속됨 CodeObject)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상