• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Sholtee / proxygen / 1060

02 May 2025 09:09AM UTC coverage: 92.623% (-0.08%) from 92.705%
1060

push

appveyor

Sholtee
fix RoslynV3 ParameterList issue

4859 of 5246 relevant lines covered (92.62%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.25
/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Event.cs
1
/********************************************************************************
2
* ClassSyntaxFactoryBase.Event.cs                                               *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9

10
using Microsoft.CodeAnalysis.CSharp;
11
using Microsoft.CodeAnalysis.CSharp.Syntax;
12

13
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
14

15
namespace Solti.Utils.Proxy.Internals
16
{
17
    internal partial class ClassSyntaxFactoryBase
18
    {
19
        /// <summary>
20
        /// <code>
21
        /// event TDelegate IInterface.EventName
22
        /// {                                    
23
        ///   add {...}                           
24
        ///   remove {...}                       
25
        /// }                                    
26
        /// </code>
27
        /// or
28
        /// <code>
29
        /// public override event TDelegate EventName
30
        /// {                                    
31
        ///   add {...}                           
32
        ///   remove {...}                       
33
        /// }                                    
34
        /// </code>
35
        /// </summary>
36
        #if DEBUG
37
        internal
38
        #endif
39
        protected EventDeclarationSyntax ResolveEvent(IEventInfo @event, CSharpSyntaxNode addBody, CSharpSyntaxNode removeBody, bool allowProtected = false)
40
        {
1✔
41
            //
42
            // Starting from .NET 5.0 interface members may have visibility.
43
            //
44

45
            Visibility.Check(@event, ContainingAssembly, allowProtected);
1✔
46

47
            EventDeclarationSyntax result = EventDeclaration
1✔
48
            (
1✔
49
                type: ResolveType(@event.Type),
1✔
50
                identifier: Identifier(@event.Name)
1✔
51
            );
1✔
52

53
            if (@event.DeclaringType.Flags.HasFlag(TypeInfoFlags.IsInterface))
1✔
54
            {
1✔
55
                CheckNotStaticAbstract(@event);
1✔
56

57
                result = result.WithExplicitInterfaceSpecifier
1✔
58
                (
1✔
59
                    explicitInterfaceSpecifier: ExplicitInterfaceSpecifier
1✔
60
                    (
1✔
61
                        (NameSyntax) ResolveType(@event.DeclaringType)
1✔
62
                    )
1✔
63
                );
1✔
64
            }
1✔
65
            else
66
            {
1✔
67
                //
68
                // Events must have add and remove accessors defined
69
                //
70

71
                IMethodInfo backingMethod = @event.AddMethod!;
1✔
72

73
                List<SyntaxKind> tokens = [.. ResolveAccessModifiers(backingMethod)];
1✔
74

75
                tokens.Add(backingMethod.IsVirtual || backingMethod.IsAbstract ? SyntaxKind.OverrideKeyword : SyntaxKind.NewKeyword);
×
76

77
                result = result.WithModifiers
×
78
                (
×
79
                    modifiers: TokenList
×
80
                    (
×
81
                        tokens.Select(Token)
×
82
                    )
×
83
                );
×
84
            }
1✔
85

86
            return result.WithAccessorList
1✔
87
            (
1✔
88
                accessorList: AccessorList
1✔
89
                (
1✔
90
                    accessors: List
1✔
91
                    (
1✔
92
                        [
1✔
93
                            //
1✔
94
                            // Modifiers cannot be placed on event declarations
1✔
95
                            //
1✔
96

1✔
97
                            ResolveAccessor(SyntaxKind.AddAccessorDeclaration, addBody),
1✔
98
                            ResolveAccessor(SyntaxKind.RemoveAccessorDeclaration, removeBody)
1✔
99
                        ]
1✔
100
                    )
1✔
101
                )
1✔
102
            );
1✔
103
        }
1✔
104

105
        /// <summary>
106
        /// <code>
107
        /// target.Event [+|-]= ...;
108
        /// </code>
109
        /// </summary>
110
        #if DEBUG
111
        internal
112
        #endif
113
        protected AssignmentExpressionSyntax RegisterEvent(IEventInfo @event, ExpressionSyntax? target, bool add, ExpressionSyntax right, ITypeInfo? castTargetTo = null) => AssignmentExpression
1✔
114
        (
1✔
115
            kind: add ? SyntaxKind.AddAssignmentExpression : SyntaxKind.SubtractAssignmentExpression,
1✔
116
            left: MemberAccess
1✔
117
            (
1✔
118
                target,
1✔
119
                @event,
1✔
120
                castTargetTo
1✔
121
            ),
1✔
122
            right: right
1✔
123
        );
1✔
124

125
        #if DEBUG
126
        internal
127
        #endif
128
        protected virtual ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) => cls;
1✔
129

130
        #if DEBUG
131
        internal
132
        #endif
133
        protected virtual ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt) => throw new NotImplementedException();
×
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc