• 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

96.94
/SRC/Private/SyntaxFactories/ClassProxySyntaxFactory.EventInterceptorFactory.cs
1
/********************************************************************************
2
* ClassProxySyntaxFactory.EventInterceptorFactory.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.Syntax;
11

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

14
namespace Solti.Utils.Proxy.Internals
15
{
16
    internal partial class ClassProxySyntaxFactory
17
    {
18
        #if DEBUG
19
        internal
20
        #endif
21
        protected override ClassDeclarationSyntax ResolveEvents(ClassDeclarationSyntax cls, object context)
22
        {
1✔
23
            foreach (IEventInfo evt in FBaseType.Events)
1✔
24
            {
1✔
25
                IMethodInfo targetMethod = evt.AddMethod ?? evt.RemoveMethod;  
×
26
                if (targetMethod.IsAbstract || targetMethod.IsVirtual)
1✔
27
                    cls = ResolveEvent(cls, context, evt);
1✔
28
            }
1✔
29

30
            return cls;
1✔
31
        }
1✔
32

33
        /// <summary>
34
        /// <code>
35
        /// private static ExtendedMemberInfo FXxX;
36
        /// public override TCallback Event
37
        /// {
38
        ///     add
39
        ///     {
40
        ///         CurrentMethod.GetBase(ref FXxX);
41
        ///     
42
        ///         object[] args = new object[] {value};
43
        ///         
44
        ///         FInterceptor.Invoke
45
        ///         (
46
        ///             new InvocationContext
47
        ///             (
48
        ///                 this,
49
        ///                 FXxX,
50
        ///                 args =>
51
        ///                 {
52
        ///                     TCallback cb_value = (TCallback) args[0];
53
        ///                     base.Event += cb_value;         
54
        ///                     return null;    
55
        ///                 },
56
        ///                 args,
57
        ///                 new Type[] {}
58
        ///             )
59
        ///         ); 
60
        ///     }
61
        /// }
62
        /// </code>
63
        /// </summary>
64
        #if DEBUG
65
        internal
66
        #endif
67
        protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt)
68
        {
1✔
69
            if (!IsVisible(evt.AddMethod) || !IsVisible(evt.RemoveMethod))
×
70
                return cls;
×
71

72
            FieldDeclarationSyntax
1✔
73
                addField = ResolveField<ExtendedMemberInfo>
1✔
74
                (
1✔
75
                    $"F{evt.AddMethod.GetMD5HashCode()}",
1✔
76
                    @readonly: false
1✔
77
                ),
1✔
78
                removeField = ResolveField<ExtendedMemberInfo>
1✔
79
                (
1✔
80
                    $"F{evt.RemoveMethod.GetMD5HashCode()}",
1✔
81
                    @readonly: false
1✔
82
                );
1✔
83

84
            return cls.AddMembers
1✔
85
            (
1✔
86
                addField,
1✔
87
                removeField,
1✔
88
                ResolveEvent
1✔
89
                (
1✔
90
                    evt,
1✔
91
                    Block
1✔
92
                    (
1✔
93
                        BuildBody(true)
1✔
94
                    ),
1✔
95
                    Block
1✔
96
                    (
1✔
97
                        BuildBody(false)
1✔
98
                    )
1✔
99
                )
1✔
100
            );
1✔
101

102
            IEnumerable<StatementSyntax> BuildBody(bool add)
103
            {
1✔
104
                FieldDeclarationSyntax field = add ? addField : removeField;
1✔
105
                IMethodInfo backingMethod = add ? evt.AddMethod : evt.RemoveMethod;
1✔
106

107
                yield return ExpressionStatement
1✔
108
                (
1✔
109
                    InvokeMethod
1✔
110
                    (
1✔
111
                        FGetBase,
1✔
112
                        arguments: Argument
1✔
113
                        (
1✔
114
                            StaticMemberAccess(cls, field)
1✔
115
                        )
1✔
116
                    )
1✔
117
                );
1✔
118

119
                IEnumerable<StatementSyntax> interceptorInvocation = ResolveInvokeInterceptor<InvocationContext>
1✔
120
                (
1✔
121
                    backingMethod,
1✔
122
                    argsArray =>
1✔
123
                    [
1✔
124
                        Argument
1✔
125
                        (
1✔
126
                            ThisExpression()
1✔
127
                        ),
1✔
128
                        Argument
1✔
129
                        (
1✔
130
                            StaticMemberAccess(cls, field)
1✔
131
                        ),
1✔
132
                        Argument
1✔
133
                        (
1✔
134
                            backingMethod.IsAbstract ? ResolveNotImplemented() : ResolveInvokeTarget
1✔
135
                            (
1✔
136
                                backingMethod,
1✔
137
                                (_, locals) => RegisterEvent
1✔
138
                                (
1✔
139
                                    evt,
1✔
140
                                    target: BaseExpression(),
1✔
141
                                    add,
1✔
142
                                    ResolveIdentifierName
1✔
143
                                    (
1✔
144
                                        locals.Single()
1✔
145
                                    )
1✔
146
                                )
1✔
147
                            )
1✔
148
                        ),
1✔
149
                        Argument
1✔
150
                        (
1✔
151
                            ResolveIdentifierName(argsArray)
1✔
152
                        ),
1✔
153
                        Argument
1✔
154
                        (
1✔
155
                            ResolveArray<Type>([])
1✔
156
                        )
1✔
157
                    ]
1✔
158
                );
1✔
159

160
                foreach (StatementSyntax statement in interceptorInvocation)
1✔
161
                    yield return statement;
1✔
162
            }
1✔
163
        }
1✔
164
    }
165
}
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