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

Sholtee / proxygen / 985

12 Apr 2025 04:09AM UTC coverage: 91.662% (-0.3%) from 91.971%
985

push

appveyor

Sholtee
greenify tests

4903 of 5349 relevant lines covered (91.66%)

0.92 hits per line

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

97.87
/SRC/Private/SyntaxFactories/UnitSyntaxFactoryBase.cs
1
/********************************************************************************
2
* UnitSyntaxFactoryBase.cs                                                      *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System.CodeDom.Compiler;
7
using System.Collections.Generic;
8
using System.Diagnostics;
9
using System.Linq;
10
using System.Runtime.CompilerServices;
11
using System.Threading;
12

13
using Microsoft.CodeAnalysis;
14
using Microsoft.CodeAnalysis.CSharp;
15
using Microsoft.CodeAnalysis.CSharp.Syntax;
16

17
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
18

19
namespace Solti.Utils.Proxy.Internals
20
{
21
    internal abstract class UnitSyntaxFactoryBase(OutputType outputType, string containingAssembly, ReferenceCollector? referenceCollector, LanguageVersion languageVersion) : ClassSyntaxFactoryBase(containingAssembly, referenceCollector, languageVersion)
1✔
22
    {
23
        private static AttributeListSyntax Attributes(params AttributeSyntax[] attributes) => AttributeList
1✔
24
        (
1✔
25
            attributes.ToSyntaxList()
1✔
26
        );
1✔
27

28
        #if DEBUG
29
        internal
30
        #endif
31
        protected abstract IEnumerable<ClassDeclarationSyntax> ResolveClasses(object context, CancellationToken cancellation);
32

33
        public OutputType OutputType { get; } = outputType;
1✔
34

35
        public abstract string ExposedClass { get; }
36

37
        public virtual CompilationUnitSyntax ResolveUnit(object context, CancellationToken cancellation)
38
        {
1✔
39
            List<MemberDeclarationSyntax> members = [..ResolveUnitMembers(context, cancellation)];
1✔
40

41
            if (members.Any() && OutputType is OutputType.Unit)
×
42
            {
1✔
43
                members[0] = members[0] switch
1✔
44
                {
1✔
45
                    NamespaceDeclarationSyntax ns => ns.WithNamespaceKeyword
1✔
46
                    (
1✔
47
                        Token
1✔
48
                        (
1✔
49
                            leading: DisableWarnings(ns.NamespaceKeyword),
1✔
50
                            kind: SyntaxKind.NamespaceKeyword,
1✔
51
                            trailing: TriviaList()
1✔
52
                        )
1✔
53
                    ),
1✔
54
                    ClassDeclarationSyntax cls => cls.WithAttributeLists
1✔
55
                    (
1✔
56
                        cls.AttributeLists.Replace
1✔
57
                        (
1✔
58
                            //
1✔
59
                            // Due to ResolveUnitMembers(), we always have attributes
1✔
60
                            //
1✔
61

1✔
62
                            cls.AttributeLists[0],
1✔
63
                            cls.AttributeLists[0].WithOpenBracketToken
1✔
64
                            (
1✔
65
                                Token
1✔
66
                                (
1✔
67
                                    leading: DisableWarnings(cls.AttributeLists[0].OpenBracketToken),
1✔
68
                                    kind: SyntaxKind.OpenBracketToken,
1✔
69
                                    trailing: TriviaList()
1✔
70
                                )
1✔
71
                            )
1✔
72
                        )
1✔
73
                    ),
1✔
74
                    _ => members[0]
×
75
                };
1✔
76

77
                static SyntaxTriviaList DisableWarnings(SyntaxToken token) =>
78
                    //
79
                    // Disable all compiler warnings:
80
                    // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#pragma-warning
81
                    //
82

83
                    token.LeadingTrivia.Insert
1✔
84
                    (
1✔
85
                        0,
1✔
86
                        Trivia
1✔
87
                        (
1✔
88
                            PragmaWarningDirectiveTrivia
1✔
89
                            (
1✔
90
                                Token(SyntaxKind.DisableKeyword),
1✔
91
                                isActive: true
1✔
92
                            )
1✔
93
                        )
1✔
94
                    );
1✔
95
            }
1✔
96

97
            return CompilationUnit().WithMembers
1✔
98
            (
1✔
99
                List(members)
1✔
100
            );
1✔
101
        }
1✔
102

103
        #if DEBUG
104
        internal
105
        #endif
106
        protected virtual IEnumerable<MemberDeclarationSyntax> ResolveUnitMembers(object context, CancellationToken cancellation) => ResolveClasses(context, cancellation).Select
1✔
107
        (
1✔
108
            cls => cls.WithAttributeLists
1✔
109
            (
1✔
110
                SingletonList
1✔
111
                (
1✔
112
                    Attributes
1✔
113
                    (
1✔
114
                        //
1✔
115
                        // https://docs.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2019#generated-code
1✔
116
                        //
1✔
117

1✔
118
                        ResolveAttribute<GeneratedCodeAttribute>
1✔
119
                        (
1✔
120
                            "ProxyGen.NET".AsLiteral(),
1✔
121
                            GetType()
1✔
122
                                .Assembly
1✔
123
                                .GetName()
1✔
124
                                .Version
1✔
125
                                .ToString()
1✔
126
                                .AsLiteral()
1✔
127
                        ),
1✔
128

1✔
129
                        //
1✔
130
                        // See xXx.Designer.cs
1✔
131
                        //
1✔
132

1✔
133
                        ResolveAttribute<DebuggerNonUserCodeAttribute>(),
1✔
134
                        ResolveAttribute<CompilerGeneratedAttribute>()
1✔
135
                    )
1✔
136
                )
1✔
137
            )
1✔
138
        );
1✔
139
    }
140
}
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