本文整理汇总了C#中Microsoft.CSharp.CSharpCodeProvider.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCodeProvider.GetType方法的具体用法?C# CSharpCodeProvider.GetType怎么用?C# CSharpCodeProvider.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.CSharpCodeProvider
的用法示例。
在下文中一共展示了CSharpCodeProvider.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileCode
/// <summary>
/// Compiles the C sharp code.
/// </summary>
/// <returns>A <see cref="System.CodeDom.Compiler.CompilerResults"/></returns>
/// <param name="source">Source code string(s)</param>
public CompilerResults CompileCode(string[] source, string[] referencePaths)
{
Trace.Log(TraceEventType.Information, "source=string({0}), referencePaths=string({1})", source.Length, referencePaths.Length);
CSharpCodeProvider provider = new CSharpCodeProvider();
Trace.Log(TraceEventType.Verbose, "CodeProvider: {0}", provider.GetType().Name);
// Build the parameters for source compilation.
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.AddRange(referencePaths);
cp.GenerateExecutable = true;
cp.OutputAssembly = "DynamicCodeTests-Scene.dll";
cp.GenerateInMemory = false;
Trace.Log(TraceEventType.Verbose, "Compiler Parameters = {{ {0} }}", ParamsToString(cp));
// Invoke compilation.
Results = provider.CompileAssemblyFromSource(cp, source);
if (Results.Errors.Count > 0)
{
// Display compilation errors.
string errorSummary = string.Format("Compilation errors: {0}", Results.Errors.Count.ToString());
Trace.Log(TraceEventType.Information, errorSummary);
foreach (CompilerError ce in Results.Errors)
Trace.Log(TraceEventType.Verbose, ce.ToString());
}
else
{
Trace.Log(TraceEventType.Verbose, "Source built {0}successfully.", cp.GenerateExecutable ? string.Concat("into ", Results.PathToAssembly, " ") : "");
}
return Results;
}