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

Sholtee / proxygen / 885

28 Dec 2023 02:35PM UTC coverage: 92.114% (-0.1%) from 92.258%
885

push

appveyor

Sholtee
introduce partial interface implementation support

4462 of 4844 relevant lines covered (92.11%)

0.92 hits per line

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

85.71
/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 InterfaceType.Events)
1✔
22
            {
1✔
23
                IEventInfo targetEvt = GetTargetMember(ifaceEvt, TargetType.Events, SignatureEquals);
1✔
24

25
                //
26
                // Check the visibility
27
                //
28

29
                Visibility.Check
1✔
30
                (
1✔
31
                    targetEvt,
1✔
32
                    ContainingAssembly,
1✔
33
                    checkAdd: ifaceEvt.AddMethod is not null,
1✔
34
                    checkRemove: ifaceEvt.RemoveMethod is not null
1✔
35
                );
1✔
36

37
                cls = ResolveEvent(cls, ifaceEvt, targetEvt);
1✔
38
            }
1✔
39

40
            return cls;
1✔
41

42
            static bool SignatureEquals(IEventInfo targetEvent, IEventInfo ifaceEvent)
43
            {
1✔
44
                if (ifaceEvent.AddMethod is not null)
1✔
45
                {
1✔
46
                    if (targetEvent.AddMethod?.SignatureEquals(ifaceEvent.AddMethod, ignoreVisibility: true) is not true)
×
47
                        return false;
×
48
                }
1✔
49

50
                if (ifaceEvent.RemoveMethod is not null)
1✔
51
                {
1✔
52
                    if (targetEvent.RemoveMethod?.SignatureEquals(ifaceEvent.RemoveMethod, ignoreVisibility: true) is not true)
×
53
                        return false;
×
54
                }
1✔
55

56
                return true;
1✔
57
            }
1✔
58
        }
1✔
59

60
        /// <summary>
61
        /// <code>
62
        /// event TDelegate IFoo&lt;System.Int32&gt;.Event    
63
        /// {                                           
64
        ///   [MethodImplAttribute(AggressiveInlining)] 
65
        ///   add => Target.Event += value;             
66
        ///   [MethodImplAttribute(AggressiveInlining)] 
67
        ///   remove => Target.Event -= value;         
68
        /// }
69
        /// </code>
70
        /// </summary>
71
        #if DEBUG
72
        internal
73
        #endif
74
        protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo targetEvt)
75
        {
1✔
76
            IEventInfo ifaceEVt = (IEventInfo) context;
1✔
77

78
            IMethodInfo accessor = targetEvt.AddMethod ?? targetEvt.RemoveMethod!;
×
79

80
            ITypeInfo? castTargetTo = accessor.AccessModifiers is AccessModifiers.Explicit
×
81
                ? accessor.DeclaringInterfaces.Single() // Explicit event can have exactly one declaring interface
×
82
                : null;
×
83

84
            return cls.AddMembers
1✔
85
            (
1✔
86
                ResolveEvent
1✔
87
                (
1✔
88
                    ifaceEVt,
1✔
89
                    addBody: CreateBody(register: true),
1✔
90
                    removeBody: CreateBody(register: false),
1✔
91
                    forceInlining: true
1✔
92
                )
1✔
93
            );
1✔
94

95
            ArrowExpressionClauseSyntax CreateBody(bool register) => ArrowExpressionClause
1✔
96
            (
1✔
97
                expression: RegisterEvent
1✔
98
                (
1✔
99
                    targetEvt,
1✔
100
                    MemberAccess(null, Target),
1✔
101
                    register,
1✔
102
                    IdentifierName(Value),
1✔
103
                    castTargetTo
1✔
104
                )
1✔
105
            );
1✔
106
        }
1✔
107
    }
108
}
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