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

Sholtee / proxygen / 868

01 Nov 2023 05:34AM UTC coverage: 95.021% (+0.1%) from 94.922%
868

push

appveyor

Sholtee
translate some comments, minor refactor

2500 of 2631 relevant lines covered (95.02%)

5.61 hits per line

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

85.71
/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)
23
        {
6✔
24
            AccessorDeclarationSyntax declaration = AccessorDeclaration(kind);
6✔
25

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

44
            if (forceInlining) declaration = declaration.WithAttributeLists
6✔
45
            (
46
                attributeLists: ResolveMethodImplAttributeToForceInlining()
47
            );
48

49
            return declaration;
6✔
50
        }
6✔
51

52
        /// <summary>
53
        /// <code>
54
        /// new System.Object[] {..., ..., ...}
55
        /// </code>
56
        /// </summary>
57
        #if DEBUG
58
        internal
59
        #endif
60
        protected ArrayCreationExpressionSyntax ResolveArray(ITypeInfo elementType, IEnumerable<ExpressionSyntax> elements) => ArrayCreationExpression
6✔
61
        (
62
            type: ArrayType
63
            (
64
                elementType: ResolveType(elementType)
65
            )
66
            .WithRankSpecifiers
67
            (
68
                rankSpecifiers: SingletonList
69
                (
70
                    ArrayRankSpecifier
71
                    (
72
                        SingletonSeparatedList
73
                        (
74
                            elements.Any() ? OmittedArraySizeExpression() : (ExpressionSyntax) 0.AsLiteral()
75
                        )
76
                    )
77
                )
78
            ),
79
            initializer: !elements.Any() ? null : InitializerExpression(SyntaxKind.ArrayInitializerExpression).WithExpressions
80
            (
81
                expressions: elements.ToSyntaxList()
82
            )
83
        );
84

85
        /// <summary>
86
        /// <code>
87
        /// new System.Object[] {..., ..., ...}
88
        /// </code>
89
        /// </summary>
90
        #if DEBUG
91
        internal
92
        #endif
93
        protected ArrayCreationExpressionSyntax ResolveArray<T>(IEnumerable<ExpressionSyntax> elements) => ResolveArray(MetadataTypeInfo.CreateFrom(typeof(T)), elements);
6✔
94

95
        /// <summary>
96
        /// <code>
97
        /// new NameSpace.T(.., ...,)
98
        /// </code>
99
        /// </summary>
100
        #if DEBUG
101
        internal
102
        #endif
103
        protected ObjectCreationExpressionSyntax ResolveObject<T>(params ArgumentSyntax[] arguments) => ObjectCreationExpression(type: ResolveType<T>()).WithArgumentList
6✔
104
        (
105
            ArgumentList
106
            (
107
                arguments.ToSyntaxList()
108
            )
109
        );
110

111
        #if DEBUG
112
        internal
113
        #endif
114
        protected static IdentifierNameSyntax ResolveIdentifierName(LocalDeclarationStatementSyntax variable) => IdentifierName(variable.Declaration.Variables.Single().Identifier);
6✔
115

116
        #if DEBUG
117
        internal
118
        #endif
119
        protected static ArgumentSyntax ResolveArgument(LocalDeclarationStatementSyntax variable) => Argument
6✔
120
        (
121
            ResolveIdentifierName(variable)
122
        );
123

124
        #if DEBUG
125
        internal
126
        #endif
127
        protected static IdentifierNameSyntax ResolveIdentifierName(FieldDeclarationSyntax field) => IdentifierName(field.Declaration.Variables.Single()!.Identifier);
6✔
128

129
        #if DEBUG
130
        internal
131
        #endif
132
        protected static ArgumentSyntax ResolveArgument(FieldDeclarationSyntax field) => Argument
×
133
        (
134
            ResolveIdentifierName(field)
135
        );
136

137
        #if DEBUG
138
        internal
139
        #endif
140
        protected static NameSyntax ResolveIdentifierName(ClassDeclarationSyntax cls) => cls.TypeParameterList is null
6✔
141
            ? IdentifierName(cls.Identifier)
142
            : GenericName
143
            (
144
                cls.Identifier,
145
                TypeArgumentList
146
                (
147
                    cls.TypeParameterList.Parameters.ToSyntaxList(ga => (TypeSyntax) IdentifierName(ga.Identifier))
6✔
148
                )
149
            );
150
    }
151
}
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