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

Sholtee / proxygen / 1078

15 Jun 2025 07:22AM UTC coverage: 92.859% (+0.2%) from 92.61%
1078

push

appveyor

Sholtee
Merge branch 'feature/#4' into v10.0.0-preview2

# Conflicts:
#	SRC/Private/Extensions/StreamExtensions.cs

4811 of 5181 relevant lines covered (92.86%)

0.93 hits per line

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

97.73
/SRC/Private/Extensions/CodeAnalysisExtensions.cs
1
/********************************************************************************
2
* CodeAnalysisExtensions.cs                                                     *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9

10
using Microsoft.CodeAnalysis;
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
    /// <summary>
19
    /// Helper methods for various syntax related types.
20
    /// </summary>
21
    internal static class CodeAnalysisExtensions
22
    {
23
        /// <summary>
24
        /// Stringifies the given <see cref="SyntaxNode"/>.
25
        /// </summary>
26
        public static string Stringify(this SyntaxNode src, string? lineEnding = null) => src
1✔
27
            .NormalizeWhitespace(eol: lineEnding ?? Environment.NewLine)
1✔
28
            .ToFullString();
1✔
29

30
        /// <summary>
31
        /// Creates a coma separated list from the given nodes.
32
        /// </summary>
33
        public static SeparatedSyntaxList<TNode> ToSyntaxList<T, TNode>(this IEnumerable<T> src, Func<T, int, TNode> factory) where TNode : SyntaxNode
34
        {
1✔
35
            List<SyntaxNodeOrToken> nodesAndTokens = [];
1✔
36

37
            int i = 0;
1✔
38

39
            foreach (T item in src)
1✔
40
            {
1✔
41
                if (i > 0) nodesAndTokens.Add
1✔
42
                (
1✔
43
                    Token(SyntaxKind.CommaToken)
1✔
44
                );
1✔
45

46
                nodesAndTokens.Add
1✔
47
                (
1✔
48
                    factory(item, i++)
1✔
49
                );
1✔
50
            }
1✔
51

52
            return SeparatedList<TNode>(nodesAndTokens);
1✔
53
        }
1✔
54

55
        /// <summary>
56
        /// Creates a coma separated list from the given nodes.
57
        /// </summary>
58
        public static SeparatedSyntaxList<TNode> ToSyntaxList<T, TNode>(this IEnumerable<T> src, Func<T, TNode> factory) where TNode : SyntaxNode => ToSyntaxList(src, (p, i) => factory(p));
1✔
59

60
        /// <summary>
61
        /// Creates a coma separated list from the given nodes.
62
        /// </summary>
63
        public static SeparatedSyntaxList<TNode> ToSyntaxList<TNode>(this IEnumerable<TNode> src) where TNode : SyntaxNode => ToSyntaxList(src, static x => x);
1✔
64

65
        /// <summary>
66
        /// Creates a qualified (dot separated) name from the given <see cref="NameSyntax"/> list.
67
        /// </summary>
68
        public static NameSyntax Qualify(this IEnumerable<NameSyntax> parts)
69
        {
1✔
70
            int count = parts.Count();
1✔
71
            return count switch
1✔
72
            {
1✔
73
                0 => throw new InvalidOperationException(),
×
74
                1 => parts.Single(),
1✔
75
                _ => QualifiedName
1✔
76
                (
1✔
77
                    left: Qualify(parts.Take(count - 1)),
1✔
78
                    right: (SimpleNameSyntax) parts.Last()
1✔
79
                )
1✔
80
            };
1✔
81
        }
1✔
82

83
        /// <summary>
84
        /// Converts the given value to <see cref="LiteralExpressionSyntax"/>.
85
        /// </summary>
86
        public static LiteralExpressionSyntax AsLiteral(this string param) => LiteralExpression
1✔
87
        (
1✔
88
            SyntaxKind.StringLiteralExpression,
1✔
89
            Literal(param)
1✔
90
        );
1✔
91

92
        /// <summary>
93
        /// Converts the given value to <see cref="LiteralExpressionSyntax"/>.
94
        /// </summary>
95
        public static LiteralExpressionSyntax AsLiteral(this int param) => LiteralExpression
1✔
96
        (
1✔
97
            SyntaxKind.NumericLiteralExpression,
1✔
98
            Literal(param)
1✔
99
        );
1✔
100
    }
101
}
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