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

Sholtee / proxygen / 1032

26 Apr 2025 04:30AM UTC coverage: 92.643% (+1.0%) from 91.629%
1032

push

appveyor

Sholtee
+1 test case

4810 of 5192 relevant lines covered (92.64%)

0.93 hits per line

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

85.0
/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)
40
        {
1✔
41
            EventDeclarationSyntax result = EventDeclaration
1✔
42
            (
1✔
43
                type: ResolveType(@event.Type),
1✔
44
                identifier: Identifier(@event.Name)
1✔
45
            );
1✔
46

47
            if (@event.DeclaringType.Flags.HasFlag(TypeInfoFlags.IsInterface))
1✔
48
            {
1✔
49
                CheckNotStaticAbstract(@event);
1✔
50

51
                result = result.WithExplicitInterfaceSpecifier
1✔
52
                (
1✔
53
                    explicitInterfaceSpecifier: ExplicitInterfaceSpecifier
1✔
54
                    (
1✔
55
                        (NameSyntax) ResolveType(@event.DeclaringType)
1✔
56
                    )
1✔
57
                );
1✔
58
            }
1✔
59
            else
60
            {
1✔
61
                //
62
                // Events must have add and remove accessors defined
63
                //
64

65
                IMethodInfo backingMethod = @event.AddMethod!;
1✔
66

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

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

71
                result = result.WithModifiers
×
72
                (
×
73
                    modifiers: TokenList
×
74
                    (
×
75
                        tokens.Select(Token)
×
76
                    )
×
77
                );
×
78
            }
1✔
79

80
            return result.WithAccessorList
1✔
81
            (
1✔
82
                accessorList: AccessorList
1✔
83
                (
1✔
84
                    accessors: List
1✔
85
                    (
1✔
86
                        [
1✔
87
                            //
1✔
88
                            // Modifiers cannot be placed on event declarations
1✔
89
                            //
1✔
90

1✔
91
                            ResolveAccessor(SyntaxKind.AddAccessorDeclaration, addBody),
1✔
92
                            ResolveAccessor(SyntaxKind.RemoveAccessorDeclaration, removeBody)
1✔
93
                        ]
1✔
94
                    )
1✔
95
                )
1✔
96
            );
1✔
97
        }
1✔
98

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

119
        #if DEBUG
120
        internal
121
        #endif
122
        protected virtual ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context) => cls;
1✔
123

124
        #if DEBUG
125
        internal
126
        #endif
127
        protected virtual ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt) => throw new NotImplementedException();
×
128
    }
129
}
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