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

Sholtee / proxygen / 937

29 Mar 2025 07:30AM UTC coverage: 89.287% (-2.1%) from 91.359%
937

push

appveyor

Sholtee
introduce IInterceptor interface, implement method interception functionality in ClassProxySyntaxFactory

4509 of 5050 relevant lines covered (89.29%)

0.89 hits per line

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

75.27
/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Common.cs
1
/********************************************************************************
2
* ClassSyntaxFactoryBase.Common                                                 *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System.Collections.Generic;
7
using System.Diagnostics;
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 ClassSyntaxFactoryBase
18
    {
19
        // https://github.com/dotnet/roslyn/issues/4861
20
        protected const string Value = "value";
21

22
        private AccessorDeclarationSyntax ResolveAccessor(SyntaxKind kind, CSharpSyntaxNode body, bool forceInlining, params IEnumerable<SyntaxKind> modifiers)
23
        {
1✔
24
            AccessorDeclarationSyntax declaration = AccessorDeclaration(kind);
1✔
25

26
            switch (body)
1✔
27
            {
28
                case BlockSyntax block:
29
                    declaration = declaration.WithBody(block);
1✔
30
                    break;
1✔
31
                case ArrowExpressionClauseSyntax arrow:
32
                    declaration = declaration
1✔
33
                        .WithExpressionBody(arrow)
1✔
34
                        .WithSemicolonToken
1✔
35
                        (
1✔
36
                            Token(SyntaxKind.SemicolonToken)
1✔
37
                        );
1✔
38
                    break;
1✔
39
                default:
40
                    Debug.Fail("Unknown node type");
×
41
                    return null!;
×
42
            }
43

44
            if (modifiers.Any()) declaration = declaration.WithModifiers
×
45
            (
×
46
                modifiers: TokenList
×
47
                (
×
48
                    modifiers.Select(Token)
×
49
                )
×
50
            );
×
51

52
            if (forceInlining) declaration = declaration.WithAttributeLists
1✔
53
            (
1✔
54
                attributeLists: ResolveMethodImplAttributeToForceInlining()
1✔
55
            );
1✔
56

57
            return declaration;
1✔
58
        }
1✔
59

60
        private static IEnumerable<SyntaxKind> AccessModifiersToSyntaxList(AccessModifiers am) => am.SetFlags().Select
1✔
61
        (
1✔
62
            static am =>
1✔
63
            {
1✔
64
                switch (am)
1✔
65
                {
1✔
66
                    case AccessModifiers.Public: return SyntaxKind.PublicKeyword;
1✔
67
                    case AccessModifiers.Protected: return SyntaxKind.ProtectedKeyword;
1✔
68
                    case AccessModifiers.Internal: return SyntaxKind.InternalKeyword;
1✔
69
                    default:
1✔
70
                        Debug.Fail("Member not visible");
×
71
                        return SyntaxKind.None;
×
72
                }
1✔
73
            }
1✔
74
        );
1✔
75

76
        /// <summary>
77
        /// <code>
78
        /// new System.Object[] {..., ..., ...}
79
        /// </code>
80
        /// </summary>
81
        #if DEBUG
82
        internal
83
        #endif
84
        protected ArrayCreationExpressionSyntax ResolveArray(ITypeInfo elementType, IEnumerable<ExpressionSyntax> elements) => ArrayCreationExpression
1✔
85
        (
1✔
86
            type: ArrayType
1✔
87
            (
1✔
88
                elementType: ResolveType(elementType)
1✔
89
            )
1✔
90
            .WithRankSpecifiers
1✔
91
            (
1✔
92
                rankSpecifiers: SingletonList
1✔
93
                (
1✔
94
                    ArrayRankSpecifier
1✔
95
                    (
1✔
96
                        SingletonSeparatedList
1✔
97
                        (
1✔
98
                            elements.Any() ? OmittedArraySizeExpression() : (ExpressionSyntax) 0.AsLiteral()
1✔
99
                        )
1✔
100
                    )
1✔
101
                )
1✔
102
            ),
1✔
103
            initializer: !elements.Any() ? null : InitializerExpression(SyntaxKind.ArrayInitializerExpression).WithExpressions
1✔
104
            (
1✔
105
                expressions: elements.ToSyntaxList()
1✔
106
            )
1✔
107
        );
1✔
108

109
        /// <summary>
110
        /// <code>
111
        /// new System.Object[] {..., ..., ...}
112
        /// </code>
113
        /// </summary>
114
        #if DEBUG
115
        internal
116
        #endif
117
        protected ArrayCreationExpressionSyntax ResolveArray<T>(IEnumerable<ExpressionSyntax> elements) => ResolveArray(MetadataTypeInfo.CreateFrom(typeof(T)), elements);
1✔
118

119
        /// <summary>
120
        /// <code>
121
        /// new NameSpace.T(.., ...,)
122
        /// </code>
123
        /// </summary>
124
        #if DEBUG
125
        internal
126
        #endif
127
        protected ObjectCreationExpressionSyntax ResolveObject<T>(params IEnumerable<ArgumentSyntax> arguments) => ObjectCreationExpression(type: ResolveType<T>()).WithArgumentList
1✔
128
        (
1✔
129
            ArgumentList
1✔
130
            (
1✔
131
                arguments.ToSyntaxList()
1✔
132
            )
1✔
133
        );
1✔
134

135
        #if DEBUG
136
        internal
137
        #endif
138
        protected static SimpleNameSyntax ResolveIdentifierName(LocalDeclarationStatementSyntax variable) => IdentifierName(variable.Declaration.Variables.Single().Identifier);
1✔
139

140
        #if DEBUG
141
        internal
142
        #endif
143
        protected static ArgumentSyntax ResolveArgument(LocalDeclarationStatementSyntax variable) => Argument
1✔
144
        (
1✔
145
            ResolveIdentifierName(variable)
1✔
146
        );
1✔
147

148
        #if DEBUG
149
        internal
150
        #endif
151
        protected static SimpleNameSyntax ResolveIdentifierName(FieldDeclarationSyntax field) => IdentifierName(field.Declaration.Variables.Single()!.Identifier);
1✔
152

153
        #if DEBUG
154
        internal
155
        #endif
156
        protected static SimpleNameSyntax ResolveIdentifierName(ClassDeclarationSyntax cls) => cls.TypeParameterList is null
×
157
            ? IdentifierName(cls.Identifier)
×
158
            : GenericName
×
159
            (
×
160
                cls.Identifier,
×
161
                TypeArgumentList
×
162
                (
×
163
                    cls.TypeParameterList.Parameters.ToSyntaxList<TypeParameterSyntax, TypeSyntax>
×
164
                    (
×
165
                        static ga => IdentifierName(ga.Identifier)
1✔
166
                    )
×
167
                )
×
168
            );
×
169
    }
170
}
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