GeneratorSupport 열거형

정의

코드 생성기에서 코드 요소의 특정한 형식을 지원하는지 여부를 확인하는 데 사용할 식별자를 정의합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class GeneratorSupport
[System.Flags]
public enum GeneratorSupport
[System.Flags]
[System.Serializable]
public enum GeneratorSupport
[<System.Flags>]
type GeneratorSupport = 
[<System.Flags>]
[<System.Serializable>]
type GeneratorSupport = 
Public Enum GeneratorSupport
상속
GeneratorSupport
특성

필드

ArraysOfArrays 1

생성기에서 배열의 배열을 지원함을 나타냅니다.

AssemblyAttributes 4096

생성기에서 어셈블리 특성을 지원함을 나타냅니다.

ChainedConstructorArguments 32768

생성기에서 연결된 생성자 인수를 지원함을 나타냅니다.

ComplexExpressions 524288

생성기에서 복합 식을 지원함을 나타냅니다.

DeclareDelegates 512

생성기에서 대리자 선언을 지원함을 나타냅니다.

DeclareEnums 256

생성기에서 열거형 선언을 지원함을 나타냅니다.

DeclareEvents 2048

생성기에서 이벤트 선언을 지원함을 나타냅니다.

DeclareIndexerProperties 33554432

생성기에서 인덱서 속성의 선언을 지원함을 나타냅니다.

DeclareInterfaces 1024

생성기에서 인터페이스 선언을 지원함을 나타냅니다.

DeclareValueTypes 128

생성기에서 값 형식 선언을 지원함을 나타냅니다.

EntryPointMethod 2

생성기에서 프로그램 진입점 메서드 지정을 지원함을 나타냅니다. 실행 파일을 빌드할 때 사용됩니다.

GenericTypeDeclaration 16777216

생성기에서 제네릭 형식 선언을 지원함을 나타냅니다.

GenericTypeReference 8388608

생성기에서 제네릭 형식 참조를 지원함을 나타냅니다.

GotoStatements 4

생성기에서 goto 문을 지원함을 나타냅니다.

MultidimensionalArrays 8

생성기에서 다차원 배열 참조를 지원함을 나타냅니다. 현재는 CodeDom을 사용하여 다차원 배열을 인스턴스화할 수 없습니다.

MultipleInterfaceMembers 131072

생성기에서 여러 인터페이스를 구현하는 멤버의 선언을 지원함을 나타냅니다.

NestedTypes 65536

생성자가 중첩 형식의 선언을 지원함을 나타냅니다.

ParameterAttributes 8192

생성기에서 매개 변수 특성을 지원함을 나타냅니다.

PartialTypes 4194304

생성기에서 부분 형식 선언을 지원함을 나타냅니다.

PublicStaticMembers 262144

생성기에서 공용 정적 멤버를 지원함을 나타냅니다.

ReferenceParameters 16384

생성기에서 참조 및 출력 매개 변수를 지원함을 나타냅니다.

Resources 2097152

생성기에서 .NET 리소스를 사용한 컴파일을 지원함을 나타냅니다. 이러한 리소스는 어셈블리로 직접 컴파일되는 기본 리소스나 위성 어셈블리에서 참조되는 리소스일 수 있습니다.

ReturnTypeAttributes 64

생성기에서 반환 형식 특성 선언을 지원함을 나타냅니다.

StaticConstructors 16

생성기에서 정적 생성자를 지원함을 나타냅니다.

TryCatchStatements 32

생성기에서 try-catch 문을 지원함을 나타냅니다.

Win32Resources 1048576

생성기에서 Win32 리소스와의 컴파일을 지원함을 나타냅니다.

예제

다음 예제에서는 를 사용하여 CompilerParameters 다양한 컴파일러 설정 및 옵션을 지정하는 방법을 보여 줍니다.

static bool CompileCode( CodeDomProvider^ provider,
   String^ sourceFile,
   String^ exeFile )
{

   CompilerParameters^ cp = gcnew CompilerParameters;
   if ( !cp)  
   {
      return false;
   }

   // Generate an executable instead of 
   // a class library.
   cp->GenerateExecutable = true;
   
   // Set the assembly file name to generate.
   cp->OutputAssembly = exeFile;
   
   // Generate debug information.
   cp->IncludeDebugInformation = true;
   
   // Add an assembly reference.
   cp->ReferencedAssemblies->Add( "System.dll" );
   
   // Save the assembly as a physical file.
   cp->GenerateInMemory = false;
   
   // Set the level at which the compiler 
   // should start displaying warnings.
   cp->WarningLevel = 3;
   
   // Set whether to treat all warnings as errors.
   cp->TreatWarningsAsErrors = false;
   
   // Set compiler argument to optimize output.
   cp->CompilerOptions = "/optimize";
   
   // Set a temporary files collection.
   // The TempFileCollection stores the temporary files
   // generated during a build in the current directory,
   // and does not delete them after compilation.
   cp->TempFiles = gcnew TempFileCollection( ".",true );

   if ( provider->Supports( GeneratorSupport::EntryPointMethod ) )
   {
      // Specify the class that contains 
      // the main method of the executable.
      cp->MainClass = "Samples.Class1";
   }

   if ( Directory::Exists( "Resources" ) )
   {
      if ( provider->Supports( GeneratorSupport::Resources ) )
      {
         // Set the embedded resource file of the assembly.
         // This is useful for culture-neutral resources,
         // or default (fallback) resources.
         cp->EmbeddedResources->Add( "Resources\\Default.resources" );

         // Set the linked resource reference files of the assembly.
         // These resources are included in separate assembly files,
         // typically localized for a specific language and culture.
         cp->LinkedResources->Add( "Resources\\nb-no.resources" );
      }
   }

   // Invoke compilation.
   CompilerResults^ cr = provider->CompileAssemblyFromFile( cp, sourceFile );

   if ( cr->Errors->Count > 0 )
   {
      // Display compilation errors.
      Console::WriteLine( "Errors building {0} into {1}",
         sourceFile, cr->PathToAssembly );
      for each ( CompilerError^ ce in cr->Errors )
      {
         Console::WriteLine( "  {0}", ce->ToString() );
         Console::WriteLine();
      }
   }
   else
   {
      Console::WriteLine( "Source {0} built into {1} successfully.",
         sourceFile, cr->PathToAssembly );
   }

   // Return the results of compilation.
   if ( cr->Errors->Count > 0 )
   {
      return false;
   }
   else
   {
      return true;
   }
}
public static bool CompileCode(CodeDomProvider provider,
    String sourceFile,
    String exeFile)
{

    CompilerParameters cp = new CompilerParameters();

    // Generate an executable instead of
    // a class library.
    cp.GenerateExecutable = true;

    // Set the assembly file name to generate.
    cp.OutputAssembly = exeFile;

    // Generate debug information.
    cp.IncludeDebugInformation = true;

    // Add an assembly reference.
    cp.ReferencedAssemblies.Add( "System.dll" );

    // Save the assembly as a physical file.
    cp.GenerateInMemory = false;

    // Set the level at which the compiler
    // should start displaying warnings.
    cp.WarningLevel = 3;

    // Set whether to treat all warnings as errors.
    cp.TreatWarningsAsErrors = false;

    // Set compiler argument to optimize output.
    cp.CompilerOptions = "/optimize";

    // Set a temporary files collection.
    // The TempFileCollection stores the temporary files
    // generated during a build in the current directory,
    // and does not delete them after compilation.
    cp.TempFiles = new TempFileCollection(".", true);

    if (provider.Supports(GeneratorSupport.EntryPointMethod))
    {
        // Specify the class that contains
        // the main method of the executable.
        cp.MainClass = "Samples.Class1";
    }

    if (Directory.Exists("Resources"))
    {
        if (provider.Supports(GeneratorSupport.Resources))
        {
            // Set the embedded resource file of the assembly.
            // This is useful for culture-neutral resources,
            // or default (fallback) resources.
            cp.EmbeddedResources.Add("Resources\\Default.resources");

            // Set the linked resource reference files of the assembly.
            // These resources are included in separate assembly files,
            // typically localized for a specific language and culture.
            cp.LinkedResources.Add("Resources\\nb-no.resources");
        }
    }

    // Invoke compilation.
    CompilerResults cr = provider.CompileAssemblyFromFile(cp, sourceFile);

    if(cr.Errors.Count > 0)
    {
        // Display compilation errors.
        Console.WriteLine("Errors building {0} into {1}",
            sourceFile, cr.PathToAssembly);
        foreach(CompilerError ce in cr.Errors)
        {
            Console.WriteLine("  {0}", ce.ToString());
            Console.WriteLine();
        }
    }
    else
    {
        Console.WriteLine("Source {0} built into {1} successfully.",
            sourceFile, cr.PathToAssembly);
        Console.WriteLine("{0} temporary files created during the compilation.",
            cp.TempFiles.Count.ToString());
    }

    // Return the results of compilation.
    if (cr.Errors.Count > 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}
Public Shared Function CompileCode(ByVal provider As CodeDomProvider, _
ByVal sourceFile As String, ByVal exeFile As String) As Boolean

    Dim cp As New CompilerParameters()

    ' Generate an executable instead of 
    ' a class library.
    cp.GenerateExecutable = True

    ' Set the assembly file name to generate.
    cp.OutputAssembly = exeFile

    ' Generate debug information.
    cp.IncludeDebugInformation = True

    ' Add an assembly reference.
    cp.ReferencedAssemblies.Add("System.dll")

    ' Save the assembly as a physical file.
    cp.GenerateInMemory = False

    ' Set the level at which the compiler 
    ' should start displaying warnings.
    cp.WarningLevel = 3

    ' Set whether to treat all warnings as errors.
    cp.TreatWarningsAsErrors = False

    ' Set compiler argument to optimize output.
    cp.CompilerOptions = "/optimize"

    ' Set a temporary files collection.
    ' The TempFileCollection stores the temporary files
    ' generated during a build in the current directory,
    ' and does not delete them after compilation.
    cp.TempFiles = New TempFileCollection(".", True)

    If provider.Supports(GeneratorSupport.EntryPointMethod) Then
        ' Specify the class that contains
        ' the main method of the executable.
        cp.MainClass = "Samples.Class1"
    End If


    If Directory.Exists("Resources") Then
        If provider.Supports(GeneratorSupport.Resources) Then
            ' Set the embedded resource file of the assembly.
            ' This is useful for culture-neutral resources,
            ' or default (fallback) resources.
            cp.EmbeddedResources.Add("Resources\Default.resources")

            ' Set the linked resource reference files of the assembly.
            ' These resources are included in separate assembly files,
            ' typically localized for a specific language and culture.
            cp.LinkedResources.Add("Resources\nb-no.resources")
        End If
    End If

    ' Invoke compilation.
    Dim cr As CompilerResults = _
        provider.CompileAssemblyFromFile(cp, sourceFile)

    If cr.Errors.Count > 0 Then
        ' Display compilation errors.
        Console.WriteLine("Errors building {0} into {1}", _
            sourceFile, cr.PathToAssembly)
        Dim ce As CompilerError
        For Each ce In cr.Errors
            Console.WriteLine("  {0}", ce.ToString())
            Console.WriteLine()
        Next ce
    Else
        Console.WriteLine("Source {0} built into {1} successfully.", _
            sourceFile, cr.PathToAssembly)
        Console.WriteLine("{0} temporary files created during the compilation.", _
                cp.TempFiles.Count.ToString())
    End If

    ' Return the results of compilation.
    If cr.Errors.Count > 0 Then
        Return False
    Else
        Return True
    End If
End Function 'CompileCode

설명

이러한 식별자는 코드 생성기의 메서드를 호출 Supports 하여 코드 생성기가 특정 유형의 코드 생성을 지원하는지 여부를 결정하는 데 사용됩니다.

적용 대상

추가 정보