Esempio n. 1
0
            public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
            {
                if (generator.GetAttributes(node).Any(attr => generator.GetName(attr) == "CompilerGenerated"))
                {
                    return(base.VisitEventDeclaration(node));
                }

                var parameters = new[] { Parameter(Identifier("value")).WithType(node.Type) };

                node = node.WithAccessorList(
                    AccessorList(
                        List(new AccessorDeclarationSyntax[]
                {
                    AccessorDeclaration(SyntaxKind.AddAccessorDeclaration)
                    .WithExpressionBody(
                        ArrowExpressionClause(ExecutePipeline(node.Type, parameters)))
                    .WithSemicolon(),
                    AccessorDeclaration(SyntaxKind.RemoveAccessorDeclaration)
                    .WithExpressionBody(
                        ArrowExpressionClause(ExecutePipeline(node.Type, parameters)))
                    .WithSemicolon()
                })));

                return(base.VisitEventDeclaration(node));
            }
        /// <summary>
        /// event TDelegate IInterface.EventName <br/>
        /// {                                    <br/>
        ///   add{...}                           <br/>
        ///   remove{...}                        <br/>
        /// }                                    <br/>
        /// </summary>
        protected internal virtual EventDeclarationSyntax DeclareEvent(IEventInfo @event, CSharpSyntaxNode?addBody = null, CSharpSyntaxNode?removeBody = null, bool forceInlining = false)
        {
            Debug.Assert(@event.DeclaringType.IsInterface);

            EventDeclarationSyntax result = EventDeclaration
                                            (
                type: CreateType(@event.Type),
                identifier: Identifier(@event.Name)
                                            )
                                            .WithExplicitInterfaceSpecifier
                                            (
                explicitInterfaceSpecifier: ExplicitInterfaceSpecifier((NameSyntax)CreateType(@event.DeclaringType))
                                            );

            List <AccessorDeclarationSyntax> accessors = new List <AccessorDeclarationSyntax>();

            if (@event.AddMethod != null && addBody != null)
            {
                accessors.Add(DeclareAccessor(SyntaxKind.AddAccessorDeclaration, addBody, forceInlining));
            }

            if (@event.RemoveMethod != null && removeBody != null)
            {
                accessors.Add(DeclareAccessor(SyntaxKind.RemoveAccessorDeclaration, removeBody, forceInlining));
            }

            return(!accessors.Any() ? result : result.WithAccessorList
                   (
                       accessorList: AccessorList
                       (
                           accessors: List(accessors)
                       )
                   ));
        }
Esempio n. 3
0
        public static EventDeclarationSyntax WithAccessor(
            this EventDeclarationSyntax syntax,
            SyntaxKind kind,
            AccessorDeclarationSyntax accessor)
        {
            AccessorListSyntax accessorList = syntax.AccessorList;

            return(syntax.WithAccessorList(
                       accessorList.WithAccessors(accessorList.Accessors.Replace(GetAccessor(syntax, kind), accessor))));
        }
        protected EventDeclarationSyntax ResolveEvent(IEventInfo @event, CSharpSyntaxNode?addBody, CSharpSyntaxNode?removeBody, bool forceInlining = false)
        {
            Debug.Assert(@event.DeclaringType.IsInterface);

            EventDeclarationSyntax result = EventDeclaration
                                            (
                type: ResolveType(@event.Type),
                identifier: Identifier(@event.Name)
                                            )
                                            .WithExplicitInterfaceSpecifier
                                            (
                explicitInterfaceSpecifier: ExplicitInterfaceSpecifier
                (
                    (NameSyntax)ResolveType(@event.DeclaringType)
                )
                                            );

            List <AccessorDeclarationSyntax> accessors = new(2);

            if (@event.AddMethod is not null && addBody is not null)
            {
                accessors.Add
                (
                    ResolveAccessor(SyntaxKind.AddAccessorDeclaration, addBody, forceInlining)
                );
            }

            if (@event.RemoveMethod is not null && removeBody is not null)
            {
                accessors.Add
                (
                    ResolveAccessor(SyntaxKind.RemoveAccessorDeclaration, removeBody, forceInlining)
                );
            }

            return(!accessors.Some() ? result : result.WithAccessorList
                   (
                       accessorList: AccessorList
                       (
                           accessors: List(accessors)
                       )
                   ));
        }
Esempio n. 5
0
        public override SyntaxNode VisitEventDeclaration(EventDeclarationSyntax node)
        {
            var parameters = new[] { Parameter(Identifier("value")).WithType(node.Type) };

            node = node.WithAccessorList(
                AccessorList(
                    List(new AccessorDeclarationSyntax[]
            {
                AccessorDeclaration(SyntaxKind.AddAccessorDeclaration)
                .WithExpressionBody(
                    ArrowExpressionClause(ExecutePipeline(node.Type, parameters)))
                .WithSemicolon(),
                AccessorDeclaration(SyntaxKind.RemoveAccessorDeclaration)
                .WithExpressionBody(
                    ArrowExpressionClause(ExecutePipeline(node.Type, parameters)))
                .WithSemicolon()
            })));

            return(base.VisitEventDeclaration(node));
        }