Export (0) Print
Expand All

BuildProvider.CodeCompilerType Property

Represents the compiler type used by a build provider to generate source code for a custom file type.

Namespace: System.Web.Compilation
Assembly: System.Web (in system.web.dll)

public virtual CompilerType CodeCompilerType { get; }
/** @property */
public CompilerType get_CodeCompilerType ()

public function get CodeCompilerType () : CompilerType

Not applicable.

Property Value

A read-only System.Web.Compilation.CompilerType representing the code generator, code compiler, and compiler settings used to build source code for the virtual path. The base class returns a null reference (Nothing in Visual Basic).

Use the CodeCompilerType property to provide the settings for compiling source code for an implementation of BuildProvider. The CodeCompilerType property is a null reference (Nothing in Visual Basic) if the build provider does not require a specific code language for generating and compiling source code.

To set the value for a CompilerType object within a build provider implementation, use the GetDefaultCompilerType or GetDefaultCompilerTypeForLanguage method.

The CodeDomProviderType property specifies the CodeDomProvider implementation that is used to generate and compile source code for a build provider. The CompilerParameters property defines the settings that are used to compile the source code into an assembly.

The following code example illustrates a simple build provider implementation, inheriting from the abstract BuildProvider base class. The build provider overrides the CodeCompilerType, GetGeneratedType, and GenerateCode members of the base class.

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);
    }
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft