25 Ekim 2016 Salı

CompilerResults Sınıfı

Giriş
Şu satırı dahil ederiz.
using System.CodeDom.Compiler;
CompiledAssembly Alanı
Şöyle yaparız.
object o = compileResult.CompiledAssembly.CreateInstance ("Foo.Bar");
Şöyle yaparız.
var method = compileResult.CompiledAssembly.GetType("ExecClass")
.GetMethod("Exec", System.Reflection.BindingFlags.Static | 
                   System.Reflection.BindingFlags.NonPublic);
method.Invoke(null, invokeArgs);
Errors Alanı
Şöyle yaparız.
if (compileResult.Errors.Count != 0)  throw new Exception("Mission failed!");
Şöyle yaparız.
var compileResult = new CSharpCodeProvider().CompileAssemblyFromSource(...);
if (compileResult.Errors.HasErrors)
{
  foreach (CompilerError ce in compileResult.Errors)
  {
    if (ce.IsWarning) continue;
    Console.WriteLine("{0}({1},{2}: error {3}: {4}", 
      ce.FileName, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText);
  }
}

Hiç yorum yok:

Yorum Gönder