다음을 통해 공유


BuildProvider.CodeCompilerType 속성

정의

빌드 공급자가 사용자 지정 파일 형식에 대한 소스 코드를 생성하는 데 사용하는 컴파일러 형식을 나타냅니다.

public:
 virtual property System::Web::Compilation::CompilerType ^ CodeCompilerType { System::Web::Compilation::CompilerType ^ get(); };
public virtual System.Web.Compilation.CompilerType CodeCompilerType { get; }
member this.CodeCompilerType : System.Web.Compilation.CompilerType
Public Overridable ReadOnly Property CodeCompilerType As CompilerType

속성 값

가상 경로에 대한 소스 코드를 빌드하는 데 사용되는 코드 생성기, 코드 컴파일러 및 컴파일러 설정을 나타내는 읽기 전용 CompilerType 입니다. 기본 클래스는 .를 반환합니다 null.

예제

다음 코드 예제에서는 추상 BuildProvider 기본 클래스에서 상속되는 간단한 빌드 공급자 구현을 보여 줍니다. 빌드 공급자는 기본 클래스의 CodeCompilerTypeGetGeneratedTypeGenerateCode 멤버를 재정의합니다.

using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Compilation;
using System.CodeDom.Compiler;
using System.CodeDom;
using System.Security;
using System.Security.Permissions;

// Define a simple build provider implementation.
[PermissionSet(SecurityAction.Demand, Unrestricted = true)]
public class SampleBuildProvider : BuildProvider
{
    // Define an internal member for the compiler type.
    protected CompilerType _compilerType = null;

    public SampleBuildProvider()
    {
        _compilerType = GetDefaultCompilerTypeForLanguage("C#");
    }

    // Return the internal CompilerType member 
    // defined in this implementation.
    public override CompilerType CodeCompilerType
    {
        get { return _compilerType; }
    }

    // Define the build provider implementation of the GenerateCode method.
    public override void GenerateCode(AssemblyBuilder assemBuilder)
    {
        // Generate a code compile unit, and add it to
        // the assembly builder.

        TextWriter tw = assemBuilder.CreateCodeFile(this);
        if (tw != null)
        {
            try
            {
                // Generate the code compile unit from the virtual path.
                CodeCompileUnit compileUnit = SampleClassGenerator.BuildCompileUnitFromPath(VirtualPath);

                // Generate the source for the code compile unit, 
                // and write it to a file specified by the assembly builder.
                CodeDomProvider provider = assemBuilder.CodeDomProvider;
                provider.GenerateCodeFromCompileUnit(compileUnit, tw, null);
            }
            finally
            {
                tw.Close();
            }
        }
    }

    public override System.Type GetGeneratedType(CompilerResults results)
    {
        string typeName = SampleClassGenerator.TypeName;

        return results.CompiledAssembly.GetType(typeName);
    }
}
Imports System.Collections
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Compilation
Imports System.CodeDom.Compiler
Imports System.CodeDom
Imports System.Security
Imports System.Security.Permissions

<PermissionSet(SecurityAction.Demand, Unrestricted := true)> _
Public Class SampleBuildProvider
    Inherits BuildProvider

    Protected _compilerType As CompilerType = Nothing

    Public Sub New()
        _compilerType = GetDefaultCompilerType()
    End Sub

    ' Return the internal CompilerType member 
    ' defined in this implementation.
    Public Overrides ReadOnly Property CodeCompilerType() As CompilerType
        Get
            CodeCompilerType = _compilerType
        End Get
    End Property


    ' Define the build provider implementation of the GenerateCode method.
    Public Overrides Sub GenerateCode(ByVal assemBuilder As AssemblyBuilder)
        ' Generate a code compile unit, and add it to
        ' the assembly builder.

        Dim tw As TextWriter = assemBuilder.CreateCodeFile(Me)
        If Not tw Is Nothing Then
            Try
                ' Generate the code compile unit from the virtual path.
                Dim compileUnit As CodeCompileUnit = _
                        SampleClassGenerator.BuildCompileUnitFromPath(VirtualPath)

                ' Generate the source for the code compile unit, 
                ' and write it to a file specified by the assembly builder.
                Dim provider As CodeDomProvider = assemBuilder.CodeDomProvider
                provider.GenerateCodeFromCompileUnit(compileUnit, tw, Nothing)
            Finally
                tw.Close()
            End Try

        End If
    End Sub

    Public Overrides Function GetGeneratedType(ByVal results As CompilerResults) As System.Type
        Dim typeName As String = SampleClassGenerator.TypeName

        Return results.CompiledAssembly.GetType(typeName)
    End Function

End Class

설명

속성을 CodeCompilerType 사용 하 여의 구현 BuildProvider에 대 한 소스 코드를 컴파일 하기 위한 설정을 제공 합니다. 속성 CodeCompilerTypenull 빌드 공급자가 소스 코드를 생성하고 컴파일하는 데 특정 코드 언어가 필요하지 않은 경우입니다.

빌드 공급자 구현 내에서 개체의 CompilerType 값을 설정하려면 해당 또는 GetDefaultCompilerTypeForLanguage 메서드를 GetDefaultCompilerType 사용합니다.

이 속성은 CodeDomProviderType 빌드 공급자에 CodeDomProvider 대한 소스 코드를 생성하고 컴파일하는 데 사용되는 구현을 지정합니다. 이 속성은 CompilerParameters 소스 코드를 어셈블리로 컴파일하는 데 사용되는 설정을 정의합니다.

적용 대상

추가 정보