Ejemplo n.º 1
0
        public static void AddMacro(MethodDeclarationSyntax macro, string namespaceName, string className)
        {
            string methodName = macro.Identifier.ToString();

            var assemblies = new[]
            {
                typeof(SyntaxNode).GetTypeInfo().Assembly.Location,
                typeof(SyntaxFactory).GetTypeInfo().Assembly.Location,
            };

            var program = MacroCompilationUnit
                          .AddMembers(NamespaceDeclaration(IdentifierName(namespaceName))
                                      .AddMembers(ClassDeclaration(className)
                                                  .AddMembers(macro
                                                              .AddModifiers(new[] { Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword) }))));

            MacroStore[methodName] = new Lazy <MethodInfo>(() =>
            {
                var stream    = Compiler.Compile(namespaceName, assemblies, OutputType.DynamicallyLinkedLibrary, program);
                var macroFunc = AssemblyRunner.GetFunction(stream, namespaceName, className, methodName);
                return(macroFunc);
            });
        }