本文整理汇总了C#中System.Web.Compilation.BuildProvider类的典型用法代码示例。如果您正苦于以下问题:C# BuildProvider类的具体用法?C# BuildProvider怎么用?C# BuildProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BuildProvider类属于System.Web.Compilation命名空间,在下文中一共展示了BuildProvider类的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);
}
}
开发者ID:.NET开发者,项目名称:System.Web.Compilation,代码行数:64,代码来源:BuildProvider
注:本文中的System.Web.Compilation.BuildProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论