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

Sholtee / proxygen / 1046

27 Apr 2025 01:21PM UTC coverage: 92.705% (+0.6%) from 92.112%
1046

push

appveyor

Sholtee
Merge branch 'v10-preview1'

4791 of 5168 relevant lines covered (92.71%)

0.93 hits per line

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

86.36
/SRC/Private/SyntaxFactories/DuckSyntaxFactory.EventInterceptorFactory.cs
1
/********************************************************************************
2
* DuckSyntaxFactory.EventInterceptorFactory.cs                                  *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System.Linq;
7

8
using Microsoft.CodeAnalysis.CSharp.Syntax;
9

10
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
11

12
namespace Solti.Utils.Proxy.Internals
13
{
14
    internal partial class DuckSyntaxFactory
15
    {
16
        #if DEBUG
17
        internal
18
        #endif
19
        protected override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context)
20
        {
1✔
21
            foreach (IEventInfo ifaceEvt in FInterfaceType.Events)
1✔
22
            {
1✔
23
                IEventInfo targetEvt = GetTargetMember
1✔
24
                (
1✔
25
                    ifaceEvt,
1✔
26
                    TargetType!.Events,
1✔
27
                    static (targetEvent, ifaceEvent) =>
1✔
28
                        targetEvent.AddMethod.SignatureEquals(ifaceEvent.AddMethod, ignoreVisibility: true) &&
×
29
                        targetEvent.RemoveMethod.SignatureEquals(ifaceEvent.RemoveMethod, ignoreVisibility: true)
×
30
                );
1✔
31

32
                cls = ResolveEvent(cls, ifaceEvt, targetEvt);
1✔
33
            }
1✔
34

35
            return cls;
1✔
36
        }
1✔
37

38
        /// <summary>
39
        /// <code>
40
        /// event TDelegate IFoo&lt;System.Int32&gt;.Event    
41
        /// {                                            
42
        ///   add => Target.Event += value;             
43
        ///   remove => Target.Event -= value;         
44
        /// }
45
        /// </code>
46
        /// </summary>
47
        #if DEBUG
48
        internal
49
        #endif
50
        protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo targetEvt)
51
        {
1✔
52
            IEventInfo ifaceEvt = (IEventInfo) context;
1✔
53

54
            Visibility.Check(targetEvt, ContainingAssembly);
1✔
55

56
            //
57
            // Starting from .NET 5.0 interface members may have visibility.
58
            //
59

60
            Visibility.Check(ifaceEvt, ContainingAssembly);
1✔
61

62
            IMethodInfo accessor = targetEvt.AddMethod ?? targetEvt.RemoveMethod!;
×
63

64
            //
65
            // Explicit members cannot be accessed directly
66
            //
67

68
            ITypeInfo? castTargetTo = accessor.AccessModifiers is AccessModifiers.Explicit
×
69
                ? accessor.DeclaringInterfaces.Single() // Explicit event can have exactly one declaring interface
×
70
                : null;
×
71

72
            return cls.AddMembers
1✔
73
            (
1✔
74
                ResolveEvent
1✔
75
                (
1✔
76
                    ifaceEvt,
1✔
77
                    addBody: CreateBody(register: true),
1✔
78
                    removeBody: CreateBody(register: false)
1✔
79
                )
1✔
80
            );
1✔
81

82
            ArrowExpressionClauseSyntax CreateBody(bool register) => ArrowExpressionClause
1✔
83
            (
1✔
84
                expression: RegisterEvent
1✔
85
                (
1✔
86
                    targetEvt,
1✔
87
                    GetTarget(),
1✔
88
                    register,
1✔
89
                    FValue,
1✔
90
                    castTargetTo
1✔
91
                )
1✔
92
            );
1✔
93
        }
1✔
94
    }
95
}
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