本文整理汇总了C#中Microsoft.VisualBasic.VBCodeProvider.CompileAssemblyFromDom方法的典型用法代码示例。如果您正苦于以下问题:C# VBCodeProvider.CompileAssemblyFromDom方法的具体用法?C# VBCodeProvider.CompileAssemblyFromDom怎么用?C# VBCodeProvider.CompileAssemblyFromDom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualBasic.VBCodeProvider
的用法示例。
在下文中一共展示了VBCodeProvider.CompileAssemblyFromDom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
internal static TemplateCompilationResult Compile(
Type templateType,
string templateBody,
IEnumerable<string> assemblyFileNames,
IEnumerable<string> namespaces,
string tempDirectory)
{
LoadRuntimeBinder();
string className;
var compileUnit = GetCodeCompileUnit(templateType, namespaces, templateBody, out className);
string sourceCode;
CodeDomProvider codeProvider;
switch (Language)
{
case TemplateCompilationLanguage.CSharp:
codeProvider = new CSharpCodeProvider();
break;
case TemplateCompilationLanguage.VisualBasic:
codeProvider = new VBCodeProvider();
break;
default:
throw new NotSupportedException("Language not supported.");
}
var builder = new StringBuilder();
using (var writer = new StringWriter(builder, CultureInfo.InvariantCulture))
{
codeProvider.GenerateCodeFromCompileUnit(compileUnit, writer, new CodeGeneratorOptions());
sourceCode = builder.ToString();
}
var parameters = CreateCompilerParameters(tempDirectory, assemblyFileNames);
var compileResult = codeProvider.CompileAssemblyFromDom(parameters, compileUnit);
if (compileResult.Errors != null && compileResult.Errors.Count > 0)
throw new TemplateCompilationException(compileResult.Errors, sourceCode, templateBody);
var fullClassName = TEMPLATES_NAMESPACE + "." + className;
return new TemplateCompilationResult
{
Type = compileResult.CompiledAssembly.GetType(fullClassName),
SourceCode = sourceCode
};
}