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

Sholtee / proxygen / 1032

26 Apr 2025 04:30AM UTC coverage: 92.643% (+1.0%) from 91.629%
1032

push

appveyor

Sholtee
+1 test case

4810 of 5192 relevant lines covered (92.64%)

0.93 hits per line

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

81.9
/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?
1✔
64
                get = null,
1✔
65
                set = null;
1✔
66

67
            if (prop.GetMethod is not null)
1✔
68
            {
1✔
69
                //
70
                // Starting from .NET 5.0 interface members may have visibility.
71
                //
72

73
                Visibility.Check(prop.GetMethod, ContainingAssembly);
1✔
74

75
                get = BuildBody
1✔
76
                (
1✔
77
                    prop.GetMethod,
1✔
78
                    (_, locals) => PropertyAccess
×
79
                    (
×
80
                        prop,
×
81
                        GetTarget(),
×
82
                        indices: locals.Select(ResolveArgument)
×
83
                    )
×
84
                );
1✔
85
            }
1✔
86

87
            if (prop.SetMethod is not null)
1✔
88
            {
1✔
89
                Visibility.Check(prop.SetMethod, ContainingAssembly);
1✔
90

91
                set = BuildBody
1✔
92
                (
1✔
93
                    prop.SetMethod,
1✔
94
                    (_, locals) => AssignmentExpression // FTarget.Prop = _value
×
95
                    (
×
96
                        kind: SyntaxKind.SimpleAssignmentExpression,
×
97
                        left: PropertyAccess
×
98
                        (
×
99
                            prop,
×
100
                            GetTarget(),
×
101
                            indices: locals
×
102
                                .Take(locals.Count - 1)
×
103
                                .Select(ResolveArgument)
×
104
                        ),
×
105
                        right: ResolveIdentifierName(locals.Last())  // "value" always the last parameter
×
106
                    )
×
107
                );
1✔
108
            }
1✔
109

110
            members.Add
1✔
111
            (
1✔
112
                prop.Indices.Any()
1✔
113
                    ? ResolveIndexer(prop, get, set)
1✔
114
                    : ResolveProperty(prop, get, set)
1✔
115
            );
1✔
116

117
            return cls.AddMembers([.. members]);
1✔
118

119
            BlockSyntax? BuildBody(IMethodInfo backingMethod, Func<IReadOnlyList<ParameterSyntax>, IReadOnlyList<LocalDeclarationStatementSyntax>, ExpressionSyntax> invocationFactory)
120
            {
1✔
121
                FieldDeclarationSyntax field = ResolveField<ExtendedMemberInfo>
1✔
122
                (
1✔
123
                    $"F{backingMethod.GetMD5HashCode()}",
1✔
124
                    @readonly: false
1✔
125
                );
1✔
126

127
                members.Add(field);
1✔
128

129
                return Block
1✔
130
                (
1✔
131
                    (StatementSyntax[])
1✔
132
                    [
1✔
133
                        ExpressionStatement
1✔
134
                        (
1✔
135
                            InvokeMethod
1✔
136
                            (
1✔
137
                                FGetImplementedInterfaceMethod,
1✔
138
                                arguments: Argument
1✔
139
                                (
1✔
140
                                    StaticMemberAccess(cls, field)
1✔
141
                                )
1✔
142
                            )
1✔
143
                        ),
1✔
144
                        ..ResolveInvokeInterceptor<InvocationContext>
1✔
145
                        (
1✔
146
                            backingMethod,
1✔
147
                            argsArray =>
1✔
148
                            [
1✔
149
                                Argument
1✔
150
                                (
1✔
151
                                    ThisExpression()
1✔
152
                                ),
1✔
153
                                Argument
1✔
154
                                (
1✔
155
                                    StaticMemberAccess(cls, field)
1✔
156
                                ),
1✔
157
                                Argument
1✔
158
                                (
1✔
159
                                    ResolveInvokeTarget(backingMethod, invocationFactory)
1✔
160
                                ),
1✔
161
                                Argument
1✔
162
                                (
1✔
163
                                    ResolveIdentifierName(argsArray)
1✔
164
                                ),
1✔
165
                                Argument
1✔
166
                                (
1✔
167
                                    ResolveArray<Type>([])
1✔
168
                                )
1✔
169
                            ]
1✔
170
                        )
1✔
171
                    ]
1✔
172
                );
1✔
173
            }
1✔
174
        }
1✔
175
    }
176
}
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