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

Sholtee / proxygen / 938

29 Mar 2025 08:32AM UTC coverage: 88.865% (-0.4%) from 89.287%
938

push

appveyor

Sholtee
throw NotImplementedException on attempt to invoke abstract base

4509 of 5074 relevant lines covered (88.86%)

0.89 hits per line

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

0.0
/SRC/Private/SyntaxFactories/ClassProxySyntaxFactory.MethodInterceptorFactory.cs
1
/********************************************************************************
2
* ClassProxySyntaxFactory.MethodInterceptorFactory.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 ResolveMethods(ClassDeclarationSyntax cls, object context)
22
        {
×
23
            foreach (IMethodInfo method in TargetType.Methods)
×
24
            {
×
25
                if (method.IsSpecial || (!method.IsAbstract && !method.IsVirtual))
×
26
                    continue;
×
27

28
                //
29
                // Check if the method is visible.
30
                //
31

32
                Visibility.Check(method, ContainingAssembly);
×
33

34

35
                cls = ResolveMethod(cls, null!, method);
×
36
            }
×
37

38
            return cls;
×
39
        }
×
40

41
        /// <summary>
42
        /// <code>
43
        /// private static ExtendedMemberInfo FXxX;
44
        /// public override TResult TGeneric1&gt;.Bar&lt;TGeneric2&gt;(TGeneric1 para1, ref T1 para2, out T2 para3, TGeneric2 para4)
45
        /// {
46
        ///     CurrentMethod.GetBase(ref FXxX);
47
        ///     
48
        ///     object[] args = new object[] {para1, para2, default(T3), para4};
49
        ///     
50
        ///     System.Object result = FInterceptor.Invoke
51
        ///     (
52
        ///         new ClassInvocationContext
53
        ///         (
54
        ///             FXxX,
55
        ///             args =>
56
        ///             {
57
        ///                 TGeneric1 cb_a = (TGeneric1) args[0];
58
        ///                 T1 cb_b;                                                                               
59
        ///                 T2 cb_c = (T2) args[2];   
60
        ///                 
61
        ///                 System.Object result;                                                                                
62
        ///                 result = base.Bar&lt;TGeneric2&gt;(cb_a, out cb_b, ref cb_c);                                  
63
        ///                                                                                                        
64
        ///                 args[1] = (System.Object) cb_b;                                                                  
65
        ///                 args[2] = (System.Object) cb_c;   
66
        ///                 
67
        ///                 return result;    
68
        ///             },
69
        ///             args,
70
        ///             new Type[] {typeof(TGeneric)}
71
        ///         )
72
        ///     );
73
        ///     
74
        ///     para2 = (T1) args[1];                                                                            
75
        ///     para3 = (T2) args[2];                                                                               
76
        ///     return (TResult) result;   
77
        /// }
78
        /// </code>
79
        /// </summary>
80
        #if DEBUG
81
        internal
82
        #endif
83
        protected override ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo targetMethod)
84
        {
×
85
            FieldDeclarationSyntax memberInfo = ResolveField<ExtendedMemberInfo>
×
86
            (
×
87
                $"F{targetMethod.GetMD5HashCode()}",
×
88
                @readonly: false
×
89
            );
×
90

91
            List<StatementSyntax> body = [];
×
92

93
            body.Add
×
94
            (
×
95
                ExpressionStatement
×
96
                (
×
97
                    InvokeMethod
×
98
                    (
×
99
                        FGetBase,
×
100
                        arguments: Argument
×
101
                        (
×
102
                            StaticMemberAccess(cls, memberInfo)
×
103
                        )
×
104
                    )
×
105
                )
×
106
            );
×
107

108
            LocalDeclarationStatementSyntax argsArray = ResolveArgumentsArray(targetMethod);
×
109
            body.Add(argsArray);
×
110

111
            InvocationExpressionSyntax invokeInterceptor = InvokeMethod
×
112
            (
×
113
                method: FInvoke,
×
114
                target: MemberAccess
×
115
                (
×
116
                    ResolveIdentifierName(FInterceptor),
×
117
                    FInvoke
×
118
                ),
×
119
                castTargetTo: null,
×
120
                arguments: Argument
×
121
                (
×
122
                    ResolveObject<ClassInvocationContext>
×
123
                    (
×
124
                        Argument
×
125
                        (
×
126
                            StaticMemberAccess(cls, memberInfo)
×
127
                        ),
×
128
                        Argument
×
129
                        (
×
130
                            targetMethod.IsAbstract ? ResolveNotImplemented() : ResolveInvokeTarget
×
131
                            (
×
132
                                targetMethod,
×
133
                                hasTarget: false,
×
134
                                (paramz, locals) => InvokeMethod
×
135
                                (
×
136
                                    targetMethod,
×
137
                                    target: BaseExpression(),
×
138
                                    castTargetTo: null,
×
139
                                    arguments: locals.Select(ResolveArgument).ToArray()
×
140
                                )
×
141
                            )
×
142
                        ),
×
143
                        Argument
×
144
                        (
×
145
                            ResolveIdentifierName(argsArray)
×
146
                        ),
×
147
                        Argument
×
148
                        (
×
149
                            ResolveArray<Type>
×
150
                            (
×
151
                                (targetMethod as IGenericMethodInfo)?.GenericArguments.Select
×
152
                                (
×
153
                                    static ga => TypeOfExpression
×
154
                                    (
×
155
                                        IdentifierName(ga.Name)
×
156
                                    )
×
157
                                ) ?? []
×
158
                            )
×
159
                        )
×
160
                    )
×
161
                )
×
162
            );
×
163

164
            LocalDeclarationStatementSyntax? result;
165
            if (targetMethod.ReturnValue.Type.IsVoid)
×
166
            {
×
167
                result = null;
×
168
                body.Add(ExpressionStatement(invokeInterceptor));
×
169
            }
×
170
            else
171
            {
×
172
                result = ResolveLocal<object>
×
173
                (
×
174
                    EnsureUnused(nameof(result), targetMethod),
×
175
                    invokeInterceptor
×
176
                );
×
177
                body.Add(result);
×
178
            }
×
179

180
            body.AddRange
×
181
            (
×
182
                AssignByRefParameters(targetMethod, argsArray)
×
183
            );
×
184

185
            if (result is not null) body.Add
×
186
            (
×
187
                ReturnResult(targetMethod.ReturnValue.Type, result)
×
188
            );
×
189

190
            return cls.AddMembers
×
191
            (
×
192
                memberInfo,
×
193
                ResolveMethod(targetMethod).WithBody
×
194
                (
×
195
                    Block(body)
×
196
                )
×
197
            );
×
198
        }
×
199
    }
200
}
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