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

Sholtee / proxygen / 976

08 Apr 2025 02:56PM UTC coverage: 91.686% (+1.6%) from 90.091%
976

push

appveyor

Sholtee
introduce PlatformAssemblies class, drop TargetFramework settings

4819 of 5256 relevant lines covered (91.69%)

0.92 hits per line

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

96.84
/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 TargetType.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 ClassInvocationContext
47
        ///             (
48
        ///                 FXxX,
49
        ///                 args =>
50
        ///                 {
51
        ///                     TCallback cb_value = (TCallback) args[0];
52
        ///                     base.Event += cb_value;         
53
        ///                     return null;    
54
        ///                 },
55
        ///                 args,
56
        ///                 new Type[] {}
57
        ///             )
58
        ///         ); 
59
        ///     }
60
        /// }
61
        /// </code>
62
        /// </summary>
63
        #if DEBUG
64
        internal
65
        #endif
66
        protected override ClassDeclarationSyntax ResolveEvent(ClassDeclarationSyntax cls, object context, IEventInfo evt)
67
        {
1✔
68
            if (!IsVisible(evt.AddMethod) || !IsVisible(evt.RemoveMethod))
×
69
                return cls;
×
70

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

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

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

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

118
                LocalDeclarationStatementSyntax argsArray = ResolveArgumentsArray(backingMethod);
1✔
119
                yield return argsArray;
1✔
120

121
                yield return ExpressionStatement
1✔
122
                (
1✔
123
                    InvokeInterceptor
1✔
124
                    (
1✔
125

1✔
126
                        Argument
1✔
127
                        (
1✔
128
                            StaticMemberAccess(cls, field)
1✔
129
                        ),
1✔
130
                        Argument
1✔
131
                        (
1✔
132
                            backingMethod.IsAbstract ? ResolveNotImplemented() : ResolveInvokeTarget
1✔
133
                            (
1✔
134
                                backingMethod,
1✔
135
                                hasTarget: false,
1✔
136
                                (_, locals) => RegisterEvent
1✔
137
                                (
1✔
138
                                    evt,
1✔
139
                                    target: BaseExpression(),
1✔
140
                                    add,
1✔
141
                                    ResolveIdentifierName
1✔
142
                                    (
1✔
143
                                        locals.Single()
1✔
144
                                    )
1✔
145
                                )
1✔
146
                            )
1✔
147
                        ),
1✔
148
                        Argument
1✔
149
                        (
1✔
150
                            ResolveIdentifierName(argsArray)
1✔
151
                        ),
1✔
152
                        Argument
1✔
153
                        (
1✔
154
                            ResolveArray<Type>([])
1✔
155
                        )
1✔
156
                    )
1✔
157
                );
1✔
158
            }
1✔
159
        }
1✔
160
    }
161
}
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