Esempio n. 1
0
 private SyntaxNode typeExtension(SyntaxNode node, SyntacticalExtension <SyntaxNode> extension)
 {
     return(CSharp.ClassDeclaration(extension.Identifier)
            .WithMembers(CSharp.List <MemberDeclarationSyntax>(new[] {
         CSharp.MethodDeclaration(CSharp.ParseTypeName("int"), "myMethod")
         .WithBody((BlockSyntax)extension.Body)
     })));
 }
Esempio n. 2
0
        private static SyntaxNode CompileFunction(SyntaxNode node, Scope scope)
        {
            var method          = (MethodDeclarationSyntax)node;
            var concurrentClass = method.Identifier.ToString() + "__concurrent";

            //create a concurrent class with the method
            var @class = CSharp.ClassDeclaration(concurrentClass)
                         .AddMembers(method);

            //add it to the parent
            var document = scope.GetDocument();

            document.change(node.Parent, AddFunctionClass(@class));

            //create a substitute call
            var invocation = Templates.FunctionInvocation
                             .Get <ExpressionStatementSyntax>(
                concurrentClass,
                method.Identifier);

            if (method.ParameterList.Parameters.Count > 0)
            {
                var invoke    = (InvocationExpressionSyntax)invocation.Expression;
                var arguments = method.ParameterList
                                .Parameters
                                .Select(parameter => CSharp.Argument(CSharp.IdentifierName(
                                                                         parameter.Identifier)))
                                .Union(invoke.ArgumentList.Arguments);

                invocation = invocation
                             .WithExpression(invoke
                                             .WithArgumentList(CSharp.ArgumentList(CSharp.SeparatedList(
                                                                                       arguments))));
            }

            return(method
                   .AddAttributeLists(CSharp.AttributeList(CSharp.SeparatedList <AttributeSyntax>(new[] {
                CSharp.Attribute(CSharp.ParseName("Concurrent"))
            })))
                   .AddParameterListParameters(Templates
                                               .FunctionParameters
                                               .Parameters
                                               .ToArray())
                   .WithBody(CSharp.Block(invocation)));
        }