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

Sholtee / proxygen / 957

03 Apr 2025 03:49AM UTC coverage: 90.283% (+3.1%) from 87.222%
957

push

appveyor

Sholtee
fix method hash generation

4841 of 5362 relevant lines covered (90.28%)

0.9 hits per line

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

94.44
/SRC/Private/SyntaxFactories/DuckSyntaxFactory.PropertyInterceptorFactory.cs
1
/********************************************************************************
2
* DuckSyntaxFactory.PropertyInterceptorFactory.cs                               *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System.Linq;
7

8
using Microsoft.CodeAnalysis.CSharp;
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 DuckSyntaxFactory
16
    {
17
        #if DEBUG
18
        internal
19
        #endif
20
        protected override ClassDeclarationSyntax ResolveProperties(ClassDeclarationSyntax cls, object context)
21
        {
1✔
22
            foreach (IPropertyInfo ifaceProperty in InterfaceType.Properties)
1✔
23
            {
1✔
24
                IPropertyInfo targetProperty = GetTargetMember(ifaceProperty, TargetType.Properties, SignatureEquals);
1✔
25

26
                //
27
                // Check if the property is visible
28
                //
29

30
                Visibility.Check
1✔
31
                (
1✔
32
                    targetProperty,
1✔
33
                    ContainingAssembly,
1✔
34
                    checkGet: ifaceProperty.GetMethod is not null,
1✔
35
                    checkSet: ifaceProperty.SetMethod is not null
1✔
36
                );
1✔
37

38
                cls = ResolveProperty(cls, ifaceProperty, targetProperty);
1✔
39
            }
1✔
40

41
            return cls;
1✔
42

43
            static bool SignatureEquals(IPropertyInfo targetProp, IPropertyInfo ifaceProp)
44
            {
1✔
45
                //
46
                // We allow the implementation to declare a getter or setter that is not required by the interface.
47
                //
48

49
                if (ifaceProp.GetMethod is not null)
1✔
50
                {
1✔
51
                    if (targetProp.GetMethod?.SignatureEquals(ifaceProp.GetMethod, ignoreVisibility: true) is not true)
×
52
                        return false;
1✔
53
                }
1✔
54

55
                if (ifaceProp.SetMethod is not null)
1✔
56
                {
1✔
57
                    if (targetProp.SetMethod?.SignatureEquals(ifaceProp.SetMethod, ignoreVisibility: true) is not true)
×
58
                        return false;
×
59
                }
1✔
60

61
                return true;
1✔
62
            }
1✔
63
        }
1✔
64

65
        /// <summary>
66
        /// <code>
67
        /// System.Int32 IFoo&lt;System.Int32&gt;.Prop 
68
        /// {                                         
69
        ///   [MethodImplAttribute(AggressiveInlining)] 
70
        ///   get => Target.Prop;                     
71
        ///   [MethodImplAttribute(AggressiveInlining)] 
72
        ///   set => Target.Prop = value;              
73
        /// }
74
        /// </code>
75
        /// </summary>
76
        #if DEBUG
77
        internal
78
        #endif
79
        protected override ClassDeclarationSyntax ResolveProperty(ClassDeclarationSyntax cls, object context, IPropertyInfo targetProperty)
80
        {
1✔
81
            IPropertyInfo ifaceProperty = (IPropertyInfo) context;
1✔
82

83
            IMethodInfo accessor = targetProperty.GetMethod ?? targetProperty.SetMethod!;
×
84

85
            //
86
            // Invoke the interface property to make sure that all indexer parameter names will match.
87
            //
88

89
            ExpressionSyntax propertyAccess = PropertyAccess
1✔
90
            (
1✔
91
                ifaceProperty,
1✔
92
                MemberAccess(null, Target),
1✔
93
                castTargetTo: accessor.AccessModifiers is AccessModifiers.Explicit
1✔
94
                    ? accessor.DeclaringInterfaces.Single() // Explicit properties belong to exactly one interface definition
1✔
95
                    : null
1✔
96
            );
1✔
97

98
            //
99
            // Accessors not defined on the interface will be ignored.
100
            //
101

102
            ArrowExpressionClauseSyntax
1✔
103
                getBody = ArrowExpressionClause
1✔
104
                (
1✔
105
                    expression: propertyAccess
1✔
106
                ),
1✔
107
                setBody = ArrowExpressionClause
1✔
108
                (
1✔
109
                    expression: AssignmentExpression
1✔
110
                    (
1✔
111
                        kind: SyntaxKind.SimpleAssignmentExpression,
1✔
112
                        left: propertyAccess,
1✔
113
                        right: IdentifierName(Value)
1✔
114
                    )
1✔
115
                );
1✔
116

117
            return cls.AddMembers
1✔
118
            (
1✔
119
                ifaceProperty.Indices.Any()
1✔
120
                    ? ResolveIndexer
1✔
121
                    (
1✔
122
                        property: ifaceProperty,
1✔
123
                        getBody: getBody,
1✔
124
                        setBody: setBody,
1✔
125
                        forceInlining: true
1✔
126
                    )
1✔
127
                    : ResolveProperty
1✔
128
                    (
1✔
129
                        property: ifaceProperty,
1✔
130
                        getBody: getBody,
1✔
131
                        setBody: setBody,
1✔
132
                        forceInlining: true
1✔
133
                    )
1✔
134
            );
1✔
135
        }
1✔
136
    }
137
}
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

© 2025 Coveralls, Inc