public void BeforeCompile(BeforeCompileContext context)
        {
            context.Diagnostics.Add(
                Diagnostic.Create(
                    new DiagnosticDescriptor("TEST", "TEST", "Hello meta programming world!", "TEST", DiagnosticSeverity.Info, true),
                    Location.None));

            context.Compilation = context.Compilation.AddSyntaxTrees(
                SyntaxFactory.ParseSyntaxTree(@"
namespace Test.Module
{
    public static class Extensions
    {
        public static T Dump<T>(this T i)
        {
            if (i != null)
            {
                System.Console.WriteLine(i);
            }
            return i;
        }
    }
}
"));
        }
 public void BeforeCompile(BeforeCompileContext context)
 {
     // NOTE: in case you need to debug your compilation module do:
     // System.Diagnostics.Debugger.Launch();
     foreach (var syntaxTree in context.Compilation.SyntaxTrees)
     {
         var model = context.Compilation.GetSemanticModel(syntaxTree);
         var rewriter = new StringBuilderInterpolationOptimizer(model);
         var rootNode = syntaxTree.GetRoot();
         var rewritten = rewriter.Visit(rootNode);
         if (rootNode != rewritten)
         {
             context.Compilation = context.Compilation.ReplaceSyntaxTree(
                 syntaxTree,
                 syntaxTree.WithRootAndOptions(rewritten, syntaxTree.Options));
         }
     }
 }
 public void Before(BeforeCompileContext context)
 {
     Apply(context, x => BeforeCompileContext = x, m => m.BeforeCompile);
 }
Esempio n. 4
0
 public void BeforeCompile(BeforeCompileContext context)
 {
     foreach (var module in modules)
         module.BeforeCompile(context);
 }