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

Sholtee / proxygen / 1060

02 May 2025 09:09AM UTC coverage: 92.623% (-0.08%) from 92.705%
1060

push

appveyor

Sholtee
fix RoslynV3 ParameterList issue

4859 of 5246 relevant lines covered (92.62%)

0.93 hits per line

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

75.53
/SRC/Private/SyntaxFactories/InterfaceProxySyntaxFactory.PropertyInterceptorFactory.cs
1
/********************************************************************************
2
* InterfaceProxySyntaxFactory.PropertyInterceptorFactory.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;
11
using Microsoft.CodeAnalysis.CSharp.Syntax;
12

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

15
namespace Solti.Utils.Proxy.Internals
16
{
17
    internal partial class InterfaceProxySyntaxFactory
18
    {
19
        #if DEBUG
20
        internal
21
        #endif
22
        protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context)
23
        {
1✔
24
            foreach (IPropertyInfo prop in TargetType!.Properties)
1✔
25
                cls = ResolveProperty(cls, context, prop);
1✔
26

27
            return base.ResolveProperties(cls, context);
1✔
28
        }
1✔
29

30
        /// <summary>
31
        /// <code>
32
        /// private static ExtendedMemberInfo FXxX;
33
        /// T Interface.Prop
34
        /// {
35
        ///     get
36
        ///     {
37
        ///         CurrentMethod.GetImplementedInterfaceMethod(ref FXxX);
38
        ///     
39
        ///         object[] args = new object[] {value};
40
        ///         
41
        ///         return (T) FInterceptor.Invoke
42
        ///         (
43
        ///             new InvocationContext
44
        ///             (
45
        ///                 this,
46
        ///                 FXxX,
47
        ///                 args => FTarget.Prop;
48
        ///                 args,
49
        ///                 new Type[] {}
50
        ///             )
51
        ///         ); 
52
        ///     }
53
        /// }
54
        /// </code>
55
        /// </summary>
56
        #if DEBUG
57
        internal
58
        #endif
59
        protected override ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo prop)
60
        {
1✔
61
            List<MemberDeclarationSyntax> members = [];
1✔
62

63
            BlockSyntax? get = prop.GetMethod is null ? null : BuildBody
×
64
            (
×
65
                prop.GetMethod,
×
66
                (_, locals) => PropertyAccess
×
67
                (
×
68
                    prop,
×
69
                    GetTarget(),
×
70
                    indices: locals.Select(ResolveArgument)
×
71
                )
×
72
            );
×
73

74
            BlockSyntax? set = prop.SetMethod is null ? null : BuildBody
1✔
75
            (
1✔
76
                prop.SetMethod,
1✔
77
                (_, locals) => AssignmentExpression // FTarget.Prop = _value
×
78
                (
×
79
                    kind: SyntaxKind.SimpleAssignmentExpression,
×
80
                    left: PropertyAccess
×
81
                    (
×
82
                        prop,
×
83
                        GetTarget(),
×
84
                        indices: locals
×
85
                            .Take(locals.Count - 1)
×
86
                            .Select(ResolveArgument)
×
87
                    ),
×
88
                    right: ResolveIdentifierName(locals.Last())  // "value" always the last parameter
×
89
                )
×
90
            );
1✔
91

92
            members.Add
1✔
93
            (
1✔
94
                prop.Indices.Any()
1✔
95
                    ? ResolveIndexer(prop, get, set)
1✔
96
                    : ResolveProperty(prop, get, set)
1✔
97
            );
1✔
98

99
            return cls.AddMembers([.. members]);
1✔
100

101
            BlockSyntax? BuildBody(IMethodInfo backingMethod, Func<IReadOnlyList<ParameterSyntax>, IReadOnlyList<LocalDeclarationStatementSyntax>, ExpressionSyntax> invocationFactory)
102
            {
1✔
103
                FieldDeclarationSyntax field = ResolveField<ExtendedMemberInfo>
1✔
104
                (
1✔
105
                    $"F{backingMethod.GetMD5HashCode()}",
1✔
106
                    @readonly: false
1✔
107
                );
1✔
108

109
                members.Add(field);
1✔
110

111
                return Block
1✔
112
                (
1✔
113
                    (StatementSyntax[])
1✔
114
                    [
1✔
115
                        ExpressionStatement
1✔
116
                        (
1✔
117
                            InvokeMethod
1✔
118
                            (
1✔
119
                                FGetImplementedInterfaceMethod,
1✔
120
                                arguments: Argument
1✔
121
                                (
1✔
122
                                    StaticMemberAccess(cls, field)
1✔
123
                                )
1✔
124
                            )
1✔
125
                        ),
1✔
126
                        ..ResolveInvokeInterceptor<InvocationContext>
1✔
127
                        (
1✔
128
                            backingMethod,
1✔
129
                            argsArray =>
1✔
130
                            [
1✔
131
                                Argument
1✔
132
                                (
1✔
133
                                    ThisExpression()
1✔
134
                                ),
1✔
135
                                Argument
1✔
136
                                (
1✔
137
                                    StaticMemberAccess(cls, field)
1✔
138
                                ),
1✔
139
                                Argument
1✔
140
                                (
1✔
141
                                    ResolveInvokeTarget(backingMethod, invocationFactory)
1✔
142
                                ),
1✔
143
                                Argument
1✔
144
                                (
1✔
145
                                    ResolveIdentifierName(argsArray)
1✔
146
                                ),
1✔
147
                                Argument
1✔
148
                                (
1✔
149
                                    ResolveArray<Type>([])
1✔
150
                                )
1✔
151
                            ]
1✔
152
                        )
1✔
153
                    ]
1✔
154
                );
1✔
155
            }
1✔
156
        }
1✔
157
    }
158
}
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