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

Sholtee / proxygen / 980

10 Apr 2025 02:40PM UTC coverage: 91.933% (+0.2%) from 91.686%
980

push

appveyor

Sholtee
test ClassProxyGenerator against system types, related fixes III

4866 of 5293 relevant lines covered (91.93%)

0.92 hits per line

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

73.33
/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Common.cs
1
/********************************************************************************
2
* ClassSyntaxFactoryBase.Common                                                 *
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
    using Properties;
19

20
    internal partial class ClassSyntaxFactoryBase
21
    {
22
        // https://github.com/dotnet/roslyn/issues/4861
23
        protected const string Value = "value";
24

25
        private static T Fail<T>(string message)
26
        {
×
27
            Debug.Fail(message);
×
28
            return default!;
×
29
        }
×
30

31
        private static AccessorDeclarationSyntax ResolveAccessor(SyntaxKind kind, CSharpSyntaxNode? body, params IEnumerable<SyntaxKind> modifiers)
32
        {
1✔
33
            AccessorDeclarationSyntax declaration = AccessorDeclaration(kind);
1✔
34

35
            declaration = body switch
1✔
36
            {
1✔
37
                BlockSyntax block => declaration.WithBody(block),
1✔
38
                ArrowExpressionClauseSyntax arrow => declaration.WithExpressionBody(arrow).WithSemicolonToken
1✔
39
                (
1✔
40
                    Token(SyntaxKind.SemicolonToken)
1✔
41
                ),
1✔
42
                null => declaration.WithSemicolonToken
1✔
43
                (
1✔
44
                    Token(SyntaxKind.SemicolonToken)
1✔
45
                ),
1✔
46
                _ => Fail<AccessorDeclarationSyntax>("Unknown node type")
×
47
            };
1✔
48

49
            if (modifiers.Any()) declaration = declaration.WithModifiers
×
50
            (
×
51
                modifiers: TokenList
×
52
                (
×
53
                    modifiers.Select(Token)
×
54
                )
×
55
            );
×
56

57
            return declaration;
1✔
58
        }
1✔
59

60
        private IEnumerable<SyntaxKind> ResolveAccessModifiers(IMethodInfo method)
61
        {
1✔
62
            bool internalAllowed = method.DeclaringType.DeclaringAssembly?.IsFriend(ContainingAssembly) is true;
×
63

64
            IEnumerable<SyntaxKind> ams = method
1✔
65
                .AccessModifiers
1✔
66
                .SetFlags()
1✔
67

1✔
68
                //
1✔
69
                // When overriding an "internal protected" member we cannot reuse the "internal" keyword
1✔
70
                // if the base is declared in a different assembly
1✔
71
                //
1✔
72

1✔
73
                .Where(am => am >= AccessModifiers.Protected && (am is not AccessModifiers.Internal || internalAllowed))
×
74
                .Select
1✔
75
                (
1✔
76
                    static am => am switch
1✔
77
                    {
1✔
78
                        AccessModifiers.Public => SyntaxKind.PublicKeyword,
1✔
79
                        AccessModifiers.Protected => SyntaxKind.ProtectedKeyword,
1✔
80
                        AccessModifiers.Internal => SyntaxKind.InternalKeyword,
1✔
81
                        _ => Fail<SyntaxKind>("Member not visible")
×
82
                    }
1✔
83
                );
1✔
84
            if (!ams.Any())
1✔
85
                throw new InvalidOperationException(Resources.UNDETERMINED_ACCESS_MODIFIER);
×
86

87
            return ams;
1✔
88
        }
1✔
89

90
        /// <summary>
91
        /// <code>
92
        /// new System.Object[] {..., ..., ...}
93
        /// </code>
94
        /// </summary>
95
        #if DEBUG
96
        internal
97
        #endif
98
        protected ArrayCreationExpressionSyntax ResolveArray(ITypeInfo elementType, IEnumerable<ExpressionSyntax> elements) => ArrayCreationExpression
1✔
99
        (
1✔
100
            type: ArrayType
1✔
101
            (
1✔
102
                elementType: ResolveType(elementType)
1✔
103
            )
1✔
104
            .WithRankSpecifiers
1✔
105
            (
1✔
106
                rankSpecifiers: SingletonList
1✔
107
                (
1✔
108
                    ArrayRankSpecifier
1✔
109
                    (
1✔
110
                        SingletonSeparatedList
1✔
111
                        (
1✔
112
                            elements.Any() ? OmittedArraySizeExpression() : (ExpressionSyntax) 0.AsLiteral()
1✔
113
                        )
1✔
114
                    )
1✔
115
                )
1✔
116
            ),
1✔
117
            initializer: !elements.Any() ? null : InitializerExpression(SyntaxKind.ArrayInitializerExpression).WithExpressions
1✔
118
            (
1✔
119
                expressions: elements.ToSyntaxList()
1✔
120
            )
1✔
121
        );
1✔
122

123
        /// <summary>
124
        /// <code>
125
        /// new System.Object[] {..., ..., ...}
126
        /// </code>
127
        /// </summary>
128
        #if DEBUG
129
        internal
130
        #endif
131
        protected ArrayCreationExpressionSyntax ResolveArray<T>(IEnumerable<ExpressionSyntax> elements) => ResolveArray(MetadataTypeInfo.CreateFrom(typeof(T)), elements);
1✔
132

133
        /// <summary>
134
        /// <code>
135
        /// new NameSpace.T(.., ...,)
136
        /// </code>
137
        /// </summary>
138
        #if DEBUG
139
        internal
140
        #endif
141
        protected ObjectCreationExpressionSyntax ResolveObject<T>(params IEnumerable<ArgumentSyntax> arguments) => ObjectCreationExpression(type: ResolveType<T>()).WithArgumentList
1✔
142
        (
1✔
143
            ArgumentList
1✔
144
            (
1✔
145
                arguments.ToSyntaxList()
1✔
146
            )
1✔
147
        );
1✔
148

149
        #if DEBUG
150
        internal
151
        #endif
152
        protected static SimpleNameSyntax ResolveIdentifierName(LocalDeclarationStatementSyntax variable) => IdentifierName(variable.Declaration.Variables.Single().Identifier);
1✔
153

154
        #if DEBUG
155
        internal
156
        #endif
157
        protected static ArgumentSyntax ResolveArgument(LocalDeclarationStatementSyntax variable) => Argument
1✔
158
        (
1✔
159
            ResolveIdentifierName(variable)
1✔
160
        );
1✔
161

162
        #if DEBUG
163
        internal
164
        #endif
165
        protected static SimpleNameSyntax ResolveIdentifierName(FieldDeclarationSyntax field) => IdentifierName(field.Declaration.Variables.Single()!.Identifier);
1✔
166

167
        #if DEBUG
168
        internal
169
        #endif
170
        protected static SimpleNameSyntax ResolveIdentifierName(ClassDeclarationSyntax cls) => cls.TypeParameterList is null
×
171
            ? IdentifierName(cls.Identifier)
×
172
            : GenericName
×
173
            (
×
174
                cls.Identifier,
×
175
                TypeArgumentList
×
176
                (
×
177
                    cls.TypeParameterList.Parameters.ToSyntaxList<TypeParameterSyntax, TypeSyntax>
×
178
                    (
×
179
                        static ga => IdentifierName(ga.Identifier)
1✔
180
                    )
×
181
                )
×
182
            );
×
183
    }
184
}
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