• 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

75.53
/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, 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
                case null:
40
                    declaration = declaration.WithSemicolonToken
1✔
41
                    (
1✔
42
                        Token(SyntaxKind.SemicolonToken)
1✔
43
                    );
1✔
44
                    break;
1✔
45
                default:
46
                    Debug.Fail("Unknown node type");
×
47
                    return null!;
×
48
            }
49

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

58
            return declaration;
1✔
59
        }
1✔
60

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

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

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

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

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

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

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

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