• 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

87.18
/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Property.cs
1
/********************************************************************************
2
* ClassSyntaxFactoryBase.Property.cs                                            *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Diagnostics;
9
using System.Linq;
10

11
using Microsoft.CodeAnalysis.CSharp;
12
using Microsoft.CodeAnalysis.CSharp.Syntax;
13

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

16
namespace Solti.Utils.Proxy.Internals
17
{
18
    internal partial class ClassSyntaxFactoryBase
19
    {
20
        /// <summary>
21
        /// <code>
22
        /// target.Property                           
23
        /// // OR                                         
24
        /// target.Property[index]
25
        /// </code>
26
        /// </summary>
27
        #if DEBUG
28
        internal
29
        #endif
30
        protected ExpressionSyntax PropertyAccess(IPropertyInfo property, ExpressionSyntax? target, ITypeInfo? castTargetTo = null) => PropertyAccess
1✔
31
        (
1✔
32
            property, 
1✔
33
            target, 
1✔
34
            castTargetTo, 
1✔
35
            property.Indices.Select(static param => Argument(IdentifierName(param.Name)))
1✔
36
        );
1✔
37

38
        /// <summary>
39
        /// <code>
40
        /// target.Property         
41
        /// // OR        
42
        /// target.Property[index]
43
        /// </code>
44
        /// </summary>
45
        #if DEBUG
46
        internal
47
        #endif
48
        protected ExpressionSyntax PropertyAccess(IPropertyInfo property, ExpressionSyntax? target, ITypeInfo? castTargetTo = null, IEnumerable<ArgumentSyntax>? indices = null) => !property.Indices.Any()
1✔
49
            ? MemberAccess
1✔
50
            (
1✔
51
                target,
1✔
52
                property,
1✔
53
                castTargetTo
1✔
54
            )
1✔
55
            : (ExpressionSyntax) ElementAccessExpression
1✔
56
            (
1✔
57
                AmendTarget(target, property, castTargetTo),
1✔
58
                BracketedArgumentList
1✔
59
                (
1✔
60
                    arguments: indices!.ToSyntaxList()
1✔
61
                )
1✔
62
            );
1✔
63

64
        private TDeclaration ResolveProperty<TDeclaration>(IPropertyInfo property, Func<IPropertyInfo, TDeclaration> fact, CSharpSyntaxNode? getBody, CSharpSyntaxNode? setBody) where TDeclaration : BasePropertyDeclarationSyntax
65
        {
1✔
66
            TDeclaration result = fact(property);
1✔
67

68
            AccessModifiers declaredVisibility;
69

70
            if (property.DeclaringType.IsInterface)
1✔
71
            {
1✔
72
                declaredVisibility = AccessModifiers.Explicit;
1✔
73

74
                result = (TDeclaration) result.WithExplicitInterfaceSpecifier
1✔
75
                (
1✔
76
                    explicitInterfaceSpecifier: ExplicitInterfaceSpecifier
1✔
77
                    (
1✔
78
                        (NameSyntax) ResolveType(property.DeclaringType)
1✔
79
                    )
1✔
80
                );
1✔
81
            }
1✔
82
            else
83
            {
1✔
84
                declaredVisibility = (AccessModifiers) Math.Max
×
85
                (
×
86
                    (int) (property.GetMethod?.AccessModifiers ?? AccessModifiers.Unknown),
×
87
                    (int) (property.SetMethod?.AccessModifiers ?? AccessModifiers.Unknown)
×
88
                );
×
89

90
                List<SyntaxKind> tokens = AccessModifiersToSyntaxList(declaredVisibility).ToList();
1✔
91

92
                IMemberInfo underlyingMethod = property.GetMethod ?? property.SetMethod!;
×
93

94
                tokens.Add(underlyingMethod.IsVirtual || underlyingMethod.IsAbstract ? SyntaxKind.OverrideKeyword : SyntaxKind.NewKeyword);
×
95

96
                result = (TDeclaration) result.WithModifiers
×
97
                (
×
98
                    TokenList
×
99
                    (
×
100
                        tokens.Select(Token)
×
101
                    )
×
102
                );
×
103
            }
1✔
104

105
            List<AccessorDeclarationSyntax> accessors = new(2);
1✔
106

107
            if (property.GetMethod is not null) accessors.Add
1✔
108
            (
1✔
109
                ResolveAccessor(property.GetMethod, getBody, SyntaxKind.GetAccessorDeclaration)
1✔
110
            );
1✔
111

112
            if (property.SetMethod is not null) accessors.Add
1✔
113
            (
1✔
114
                ResolveAccessor(property.SetMethod, setBody, SyntaxKind.SetAccessorDeclaration)
1✔
115
            );
1✔
116

117
            return (TDeclaration) result.WithAccessorList
1✔
118
            (
1✔
119
                accessorList: AccessorList
1✔
120
                (
1✔
121
                    accessors: List(accessors)
1✔
122
                )
1✔
123
            );
1✔
124

125
            AccessorDeclarationSyntax ResolveAccessor(IMethodInfo backingMethod, CSharpSyntaxNode? body, SyntaxKind kind)
126
            {
1✔
127
                Debug.Assert(backingMethod is not null, "Backing method cannot be null");
1✔
128

129
                //
130
                // Accessor cannot have higher visibility than the property's
131
                //
132

133
                IEnumerable<SyntaxKind> modifiers = backingMethod!.AccessModifiers < declaredVisibility
1✔
134
                    ? AccessModifiersToSyntaxList(backingMethod.AccessModifiers)
1✔
135
                    : [];
1✔
136

137
                return this.ResolveAccessor(kind, body, modifiers);
1✔
138
            }
1✔
139
        }
1✔
140

141
        /// <summary>
142
        /// <code>
143
        /// int IInterface[T].Prop
144
        /// {                      
145
        ///   get{...}            
146
        ///   set{...}           
147
        /// }                    
148
        /// </code>
149
        /// or
150
        /// <code>
151
        /// public override int Prop
152
        /// {                      
153
        ///   get{...}            
154
        ///   protected set{...}           
155
        /// }                    
156
        /// </code>
157
        /// </summary>
158
        #if DEBUG
159
        internal
160
        #endif
161
        protected PropertyDeclarationSyntax ResolveProperty(IPropertyInfo property, CSharpSyntaxNode? getBody, CSharpSyntaxNode? setBody) => ResolveProperty
1✔
162
        (
1✔
163
            property,
1✔
164
            property => PropertyDeclaration
1✔
165
            (
1✔
166
                type: ResolveType(property.Type),
1✔
167
                identifier: Identifier(property.Name)
1✔
168
            ),
1✔
169
            getBody,
1✔
170
            setBody
1✔
171
        );
1✔
172

173
        /// <summary>
174
        /// <code>
175
        /// int IInterface.this[string index, ...]
176
        /// {                                     
177
        ///   get{...}                            
178
        ///   set{...}                           
179
        /// }            
180
        /// </code>
181
        /// or
182
        /// <code>
183
        /// public override int this[string index, ...]
184
        /// {                                     
185
        ///   get{...}                            
186
        ///   protected set{...}                           
187
        /// }            
188
        /// </code>
189
        /// </summary>
190
        #if DEBUG
191
        internal
192
        #endif
193
        protected IndexerDeclarationSyntax ResolveIndexer(IPropertyInfo property, CSharpSyntaxNode? getBody, CSharpSyntaxNode? setBody) => ResolveProperty
1✔
194
        (
1✔
195
            property,
1✔
196
            property => 
1✔
197
                IndexerDeclaration
1✔
198
                (
1✔
199
                    type: ResolveType(property.Type)
1✔
200
                )
1✔
201
                .WithParameterList
1✔
202
                (
1✔
203
                    parameterList: BracketedParameterList
1✔
204
                    (
1✔
205
                        parameters: property.Indices.ToSyntaxList
1✔
206
                        (
1✔
207
                            index => Parameter
1✔
208
                            (
1✔
209
                                identifier: Identifier(index.Name)
1✔
210
                            )
1✔
211
                            .WithType
1✔
212
                            (
1✔
213
                                type: ResolveType(index.Type)
1✔
214
                            )
1✔
215
                        )
1✔
216
                    )
1✔
217
                ),
1✔
218
            getBody,
1✔
219
            setBody
1✔
220
        );
1✔
221

222
        #if DEBUG
223
        internal
224
        #endif
225
        protected virtual ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context) => cls;
1✔
226

227
        #if DEBUG
228
        internal
229
        #endif
230
        protected virtual ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo property) => cls;
×
231
    }
232
}
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