Beispiel #1
0
        private static Func <SyntaxNode, Scope, SyntaxNode> EventDeclaration(IEnumerable <SyntaxToken> args)
        {
            return((node, scope) =>
            {
                EventFieldDeclarationSyntax @event = (EventFieldDeclarationSyntax)node;
                ParameterListSyntax @params = CSharp.ParseParameterList(RoslynCompiler.TokensToString(args));

                var variable = @event
                               .Declaration
                               .Variables[0];

                var delegateName = variable.Identifier.ToString() + "_delegate"; //td: unique ids
                var delegateDecl = CSharp.DelegateDeclaration(RoslynCompiler.@void, delegateName)
                                   .WithParameterList(@params)
                                   .WithModifiers(@event.Modifiers);

                //add the delegate
                var document = scope.GetDocument <SyntaxToken, SyntaxNode, SemanticModel>();
                document.change(@event.Parent, RoslynCompiler.AddMember(delegateDecl));

                return @event
                .WithDeclaration(@event.Declaration
                                 .WithType(CSharp.ParseTypeName(delegateName)));
            });
        }