本文整理汇总了C#中System.Web.Compilation.BuildProvider.GenerateCode方法的典型用法代码示例。如果您正苦于以下问题:C# BuildProvider.GenerateCode方法的具体用法?C# BuildProvider.GenerateCode怎么用?C# BuildProvider.GenerateCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Compilation.BuildProvider
的用法示例。
在下文中一共展示了BuildProvider.GenerateCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleBuildProvider
//引入命名空间
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);
}
}