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

Sholtee / proxygen / 1046

27 Apr 2025 01:21PM UTC coverage: 92.705% (+0.6%) from 92.112%
1046

push

appveyor

Sholtee
Merge branch 'v10-preview1'

4791 of 5168 relevant lines covered (92.71%)

0.93 hits per line

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

82.35
/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 ProxyUnitSyntaxFactoryBase CreateMainUnit(INamedTypeSymbol generator, CSharpCompilation compilation, SyntaxFactoryContext context)
43
        {
1✔
44
            return SourceFactories.TryGetValue(generator.GetQualifiedMetadataName()!, out ISupportsSourceGeneration ssg)
1✔
45
                ? ssg.CreateMainUnit
1✔
46
                (
1✔
47
                    generator,
1✔
48
                    compilation,
1✔
49
                    context
1✔
50
                )
1✔
51
                : throw new InvalidOperationException
1✔
52
                (
1✔
53
                    string.Format
1✔
54
                    (
1✔
55
                        SGResources.Culture,
1✔
56
                        SGResources.NOT_A_GENERATOR,
1✔
57
                        generator
1✔
58
                    )
1✔
59
                );
1✔
60
        }
1✔
61

62
        private static IEnumerable<UnitSyntaxFactoryBase> CreateChunks(CSharpCompilation compilation, SyntaxFactoryContext context)
63
        {
1✔
64
            INamedTypeSymbol? miaSym = compilation.GetTypeByMetadataName(typeof(ModuleInitializerAttribute).FullName);
1✔
65

66
            if (miaSym is not null)
1✔
67
            {
1✔
68
                //
69
                // ModuleInitializerAttribute might be defined by te user, too.
70
                //
71

72
                if (miaSym.DeclaredAccessibility is Accessibility.Public)
1✔
73
                    yield break;
1✔
74

75
                if 
×
76
                (
×
77
                    miaSym.DeclaredAccessibility is Accessibility.Internal &&     
×
78
                    (
×
79
                        SymbolEqualityComparer.Equals(miaSym.ContainingAssembly, compilation.Assembly) || 
×
80
                        miaSym.ContainingAssembly.GivesAccessTo(compilation.Assembly)
×
81
                    )
×
82
                ) 
×
83
                    yield break;
1✔
84
            }
1✔
85

86
            yield return new ModuleInitializerSyntaxFactory(context);
1✔
87
        }
1✔
88
    }
89
}
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

© 2025 Coveralls, Inc