• 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

94.17
/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
        {
1✔
23
            foreach (IMethodInfo method in TargetType.Methods)
1✔
24
            {
1✔
25
                if (method.IsSpecial || (!method.IsAbstract && !method.IsVirtual))
×
26
                    continue;
1✔
27

28
                cls = ResolveMethod(cls, context, method);
1✔
29
            }
1✔
30

31
            return cls;
1✔
32
        }
1✔
33

34
        /// <summary>
35
        /// <code>
36
        /// private static ExtendedMemberInfo FXxX;
37
        /// public override TResult TGeneric1&gt;.Bar&lt;TGeneric2&gt;(TGeneric1 para1, ref T1 para2, out T2 para3, TGeneric2 para4)
38
        /// {
39
        ///     CurrentMethod.GetBase(ref FXxX);
40
        ///     
41
        ///     object[] args = new object[] {para1, para2, default(T3), para4};
42
        ///     
43
        ///     System.Object result = FInterceptor.Invoke
44
        ///     (
45
        ///         new ClassInvocationContext
46
        ///         (
47
        ///             FXxX,
48
        ///             args =>
49
        ///             {
50
        ///                 TGeneric1 cb_a = (TGeneric1) args[0];
51
        ///                 T1 cb_b;                                                                               
52
        ///                 T2 cb_c = (T2) args[2];   
53
        ///                 
54
        ///                 System.Object result;                                                                                
55
        ///                 result = base.Bar&lt;TGeneric2&gt;(cb_a, out cb_b, ref cb_c);                                  
56
        ///                                                                                                        
57
        ///                 args[1] = (System.Object) cb_b;                                                                  
58
        ///                 args[2] = (System.Object) cb_c;   
59
        ///                 
60
        ///                 return result;    
61
        ///             },
62
        ///             args,
63
        ///             new Type[] {typeof(TGeneric)}
64
        ///         )
65
        ///     );
66
        ///     
67
        ///     para2 = (T1) args[1];                                                                            
68
        ///     para3 = (T2) args[2];                                                                               
69
        ///     return (TResult) result;   
70
        /// }
71
        /// </code>
72
        /// </summary>
73
        #if DEBUG
74
        internal
75
        #endif
76
        protected override ClassDeclarationSyntax ResolveMethod(ClassDeclarationSyntax cls, object context, IMethodInfo targetMethod)
77
        {
1✔
78
            //
79
            // Check if the method is visible.
80
            //
81

82
            if (!IsVisible(targetMethod))
1✔
83
                return cls;
×
84

85
            FieldDeclarationSyntax memberInfo = ResolveField<ExtendedMemberInfo>
1✔
86
            (
1✔
87
                $"F{targetMethod.GetMD5HashCode()}",
1✔
88
                @readonly: false
1✔
89
            );
1✔
90

91
            List<StatementSyntax> body = [];
1✔
92

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

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

111
            InvocationExpressionSyntax invokeInterceptor = InvokeInterceptor
1✔
112
            (
1✔
113
                Argument
1✔
114
                (
1✔
115
                    StaticMemberAccess(cls, memberInfo)
1✔
116
                ),
1✔
117
                Argument
1✔
118
                (
1✔
119
                    targetMethod.IsAbstract ? ResolveNotImplemented() : ResolveInvokeTarget
1✔
120
                    (
1✔
121
                        targetMethod,
1✔
122
                        hasTarget: false,
1✔
123
                        (_, locals) => InvokeMethod
1✔
124
                        (
1✔
125
                            targetMethod,
1✔
126
                            target: BaseExpression(),
1✔
127
                            castTargetTo: null,
1✔
128
                            arguments: locals.Select(ResolveArgument).ToArray()
1✔
129
                        )
1✔
130
                    )
1✔
131
                ),
1✔
132
                Argument
1✔
133
                (
1✔
134
                    ResolveIdentifierName(argsArray)
1✔
135
                ),
1✔
136
                Argument
1✔
137
                (
1✔
138
                    ResolveArray<Type>
1✔
139
                    (
1✔
140
                        (targetMethod as IGenericMethodInfo)?.GenericArguments.Select
1✔
141
                        (
1✔
142
                            static ga => TypeOfExpression
1✔
143
                            (
1✔
144
                                IdentifierName(ga.Name)
1✔
145
                            )
1✔
146
                        ) ?? []
1✔
147
                    )
1✔
148
                )
1✔
149
            );
1✔
150

151
            LocalDeclarationStatementSyntax? result;
152
            if (targetMethod.ReturnValue.Type.IsVoid)
1✔
153
            {
×
154
                result = null;
×
155
                body.Add(ExpressionStatement(invokeInterceptor));
×
156
            }
×
157
            else
158
            {
1✔
159
                result = ResolveLocal<object>
1✔
160
                (
1✔
161
                    EnsureUnused(nameof(result), targetMethod),
1✔
162
                    invokeInterceptor
1✔
163
                );
1✔
164
                body.Add(result);
1✔
165
            }
1✔
166

167
            body.AddRange
1✔
168
            (
1✔
169
                AssignByRefParameters(targetMethod, argsArray)
1✔
170
            );
1✔
171

172
            if (result is not null) body.Add
1✔
173
            (
1✔
174
                ReturnResult(targetMethod.ReturnValue.Type, result)
1✔
175
            );
1✔
176

177
            return cls.AddMembers
1✔
178
            (
1✔
179
                memberInfo,
1✔
180
                ResolveMethod(targetMethod).WithBody
1✔
181
                (
1✔
182
                    Block(body)
1✔
183
                )
1✔
184
            );
1✔
185
        }
1✔
186
    }
187
}
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

© 2025 Coveralls, Inc