• 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

80.56
/SRC/Private/SyntaxFactories/ClassProxySyntaxFactory.PropertyInterceptorFactory.cs
1
/********************************************************************************
2
* ClassProxySyntaxFactory.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 ClassProxySyntaxFactory
18
    {
19
        #if DEBUG
20
        internal
21
        #endif
22
        protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context)
23
        {
1✔
24
            foreach (IPropertyInfo prop in FBaseType.Properties)
1✔
25
            {
1✔
26
                IMethodInfo targetMethod = prop.GetMethod ?? prop.SetMethod!;
1✔
27
                if (targetMethod.IsAbstract || targetMethod.IsVirtual)
1✔
28
                    cls = ResolveProperty(cls, context, prop);
1✔
29
            }
1✔
30

31
            return base.ResolveProperties(cls, context);
1✔
32
        }
1✔
33

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

67
            BlockSyntax? get;
68
            if (prop.GetMethod is null) get = null; else
×
69
            {
1✔
70
                if (!IsVisible(prop.GetMethod))
1✔
71
                    return cls;
1✔
72

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

85
            BlockSyntax? set;
86
            if (prop.SetMethod is null) set = null; else
1✔
87
            {
1✔
88
                if (!IsVisible(prop.SetMethod))
1✔
89
                    return cls;
×
90

91
                set = BuildBody
1✔
92
                (
1✔
93
                    prop.SetMethod,
1✔
94
                    (_, locals) => AssignmentExpression // base.Prop = _value
×
95
                    (
×
96
                        kind: SyntaxKind.SimpleAssignmentExpression,
×
97
                        left: PropertyAccess
×
98
                        (
×
99
                            prop,
×
100
                            BaseExpression(),
×
101
                            indices: locals
×
102
                                .Take(locals.Count - 1)
×
103
                                .Select(ResolveArgument)
×
104
                        ),
×
105
                        right: ResolveIdentifierName(locals.Last())
×
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
                                FGetBase,
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
                                    backingMethod.IsAbstract ? ResolveNotImplemented() : 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