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

Sholtee / proxygen / 1005

17 Apr 2025 01:11PM UTC coverage: 91.501% (+1.3%) from 90.219%
1005

push

appveyor

Sholtee
greenify tests

5006 of 5471 relevant lines covered (91.5%)

0.92 hits per line

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

42.03
/SRC/Private/SourceGenerators/ProxyEmbedderBase.UnitFactory.cs
1
/********************************************************************************
2
* ProxyEmbedderBase.UnitFactory.cs                                              *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Runtime.CompilerServices;
9
using System.Reflection;
10

11
using Microsoft.CodeAnalysis;
12
using Microsoft.CodeAnalysis.CSharp;
13

14
namespace Solti.Utils.Proxy.Internals
15
{
16
    using Properties;
17

18
    internal abstract partial class ProxyEmbedderBase
19
    {
20
        private static IReadOnlyDictionary<string, ISupportsSourceGeneration> SourceFactories { get; } = GetSourceFactories();
1✔
21

22
        private static IReadOnlyDictionary<string, ISupportsSourceGeneration> GetSourceFactories()
23
        {
1✔
24
            Dictionary<string, ISupportsSourceGeneration> result = [];
1✔
25

26
            foreach (Type type in typeof(Generator).Assembly.GetExportedTypes())
1✔
27
            {
1✔
28
                SupportsSourceGenerationAttributeBase? ssg = type.GetCustomAttribute<SupportsSourceGenerationAttributeBase>();
1✔
29
                if (ssg is null)
1✔
30
                    continue;
1✔
31

32
                try
33
                {
1✔
34
                    result.Add(type.FullName, ssg);
1✔
35
                }
1✔
36
                catch {} // Don't throw in initialization phase
×
37
            }
1✔
38

39
            return result;
1✔
40
        }
1✔
41

42
        private static SyntaxFactoryContext CreateContext(CSharpCompilation compilation, Config config) => new SyntaxFactoryContext
×
43
        {
×
44
            OutputType = OutputType.Unit,
×
45
            LanguageVersion = compilation.LanguageVersion,
×
46
            AssemblyNameOverride = compilation.Assembly.Name,
×
47

×
48
            //
×
49
            // Collecting references required only when dumping the source
×
50
            //
×
51

×
52
            ReferenceCollector = config.SourceDump is not null
×
53
                ? new ReferenceCollector()
×
54
                : null,
×
55
            Config = config
×
56
        };
×
57

58
        protected static ProxyUnitSyntaxFactoryBase CreateMainUnit(INamedTypeSymbol generator, CSharpCompilation compilation, Config config)
59
        {
1✔
60
            return SourceFactories.TryGetValue(generator.GetQualifiedMetadataName()!, out ISupportsSourceGeneration ssg)
×
61
                ? ssg.CreateMainUnit
×
62
                (
×
63
                    generator,
×
64
                    compilation,
×
65
                    CreateContext(compilation, config)
×
66
                )
×
67
                : throw new InvalidOperationException
×
68
                (
×
69
                    string.Format
×
70
                    (
×
71
                        SGResources.Culture,
×
72
                        SGResources.NOT_A_GENERATOR,
×
73
                        generator
×
74
                    )
×
75
                );
×
76
        }
1✔
77

78
        protected static IEnumerable<UnitSyntaxFactoryBase> CreateChunks(CSharpCompilation compilation, Config config)
79
        {
1✔
80
            INamedTypeSymbol? miaSym = compilation.GetTypeByMetadataName(typeof(ModuleInitializerAttribute).FullName);
1✔
81

82
            if (miaSym is not null)
1✔
83
            {
1✔
84
                //
85
                // ModuleInitializerAttribute might be defined by te user, too.
86
                //
87

88
                if (miaSym.DeclaredAccessibility is Accessibility.Public)
1✔
89
                    yield break;
1✔
90

91
                if 
×
92
                (
×
93
                    miaSym.DeclaredAccessibility is Accessibility.Internal &&     
×
94
                    (
×
95
                        SymbolEqualityComparer.Equals(miaSym.ContainingAssembly, compilation.Assembly) || 
×
96
                        miaSym.ContainingAssembly.GivesAccessTo(compilation.Assembly)
×
97
                    )
×
98
                ) 
×
99
                    yield break;
1✔
100
            }
1✔
101

102
            yield return new ModuleInitializerSyntaxFactory
1✔
103
            (
1✔
104
                CreateContext(compilation, config)
1✔
105
            );
1✔
106
        }
1✔
107
    }
108
}
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