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

Sholtee / proxygen / 986

12 Apr 2025 03:05PM UTC coverage: 90.114% (-1.5%) from 91.662%
986

push

appveyor

Sholtee
DelegateProxySyntaxFactory pt II

4913 of 5452 relevant lines covered (90.11%)

0.9 hits per line

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

98.82
/SRC/Private/SyntaxFactories/ClassProxySyntaxFactory.MethodInterceptorFactory.cs
1
/********************************************************************************
2
* ClassProxySyntaxFactory.MethodInterceptorFactory.cs                           *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Linq;
8

9
using Microsoft.CodeAnalysis.CSharp.Syntax;
10

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

13
namespace Solti.Utils.Proxy.Internals
14
{
15
    internal partial class ClassProxySyntaxFactory
16
    {
17
        #if DEBUG
18
        internal
19
        #endif
20
        protected override ClassDeclarationSyntax ResolveMethods(ClassDeclarationSyntax cls, object context)
21
        {
1✔
22
            foreach (IMethodInfo method in BaseType.Methods)
1✔
23
            {
1✔
24
                if (method.IsSpecial || (!method.IsAbstract && !method.IsVirtual))
×
25
                    continue;
1✔
26

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

30
            return cls;
1✔
31
        }
1✔
32

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

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

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

90
            return cls.AddMembers
1✔
91
            (
1✔
92
                memberInfo,
1✔
93
                ResolveMethod(targetMethod).WithBody
1✔
94
                (
1✔
95
                    Block
1✔
96
                    (
1✔
97
                        (StatementSyntax[])
1✔
98
                        [
1✔
99
                            ExpressionStatement
1✔
100
                            (
1✔
101
                                InvokeMethod
1✔
102
                                (
1✔
103
                                    FGetBase,
1✔
104
                                    arguments: Argument
1✔
105
                                    (
1✔
106
                                        StaticMemberAccess(cls, memberInfo)
1✔
107
                                    )
1✔
108
                                )
1✔
109
                            ),
1✔
110
                            ..ResolveInvokeInterceptor<ClassInvocationContext>
1✔
111
                            (
1✔
112
                                targetMethod,
1✔
113
                                argsArray =>
1✔
114
                                [
1✔
115
                                    Argument
1✔
116
                                    (
1✔
117
                                        StaticMemberAccess(cls, memberInfo)
1✔
118
                                    ),
1✔
119
                                    Argument
1✔
120
                                    (
1✔
121
                                        targetMethod.IsAbstract ? ResolveNotImplemented() : ResolveInvokeTarget
1✔
122
                                        (
1✔
123
                                            targetMethod,
1✔
124
                                            hasTarget: false,
1✔
125
                                            (_, locals) => InvokeMethod
1✔
126
                                            (
1✔
127
                                                targetMethod,
1✔
128
                                                target: BaseExpression(),
1✔
129
                                                castTargetTo: null,
1✔
130
                                                arguments: locals.Select(ResolveArgument).ToArray()
1✔
131
                                            )
1✔
132
                                        )
1✔
133
                                    ),
1✔
134
                                    Argument
1✔
135
                                    (
1✔
136
                                        ResolveIdentifierName(argsArray)
1✔
137
                                    ),
1✔
138
                                    Argument
1✔
139
                                    (
1✔
140
                                        ResolveArray<Type>
1✔
141
                                        (
1✔
142
                                            (targetMethod as IGenericMethodInfo)?.GenericArguments.Select
1✔
143
                                            (
1✔
144
                                                static ga => TypeOfExpression
1✔
145
                                                (
1✔
146
                                                    IdentifierName(ga.Name)
1✔
147
                                                )
1✔
148
                                            ) ?? []
1✔
149
                                        )
1✔
150
                                    )
1✔
151
                                ]
1✔
152
                            )
1✔
153
                        ]
1✔
154
                    )
1✔
155
                )
1✔
156
            );
1✔
157
        }
1✔
158
    }
159
}
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