-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAutoLoggerMessageGenerator.cs
More file actions
44 lines (38 loc) · 1.58 KB
/
AutoLoggerMessageGenerator.cs
File metadata and controls
44 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Text;
using AutoLoggerMessageGenerator.Configuration;
using AutoLoggerMessageGenerator.Emitters;
using AutoLoggerMessageGenerator.ReferenceAnalyzer;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace AutoLoggerMessageGenerator.Generators;
[Generator]
public partial class AutoLoggerMessageGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var configuration = GeneratorOptionsProvider.Provide(context);
var modulesProvider = context.GetMetadataReferencesProvider()
.SelectMany(static (reference, _) => reference.GetModules())
.Collect()
.WithTrackingName("Scanning project references");
GenerateLoggerMessages(context, configuration, modulesProvider);
GenerateLoggerScopes(context, configuration);
GenerateInterceptorAttribute(context, configuration);
}
private static void GenerateInterceptorAttribute(
IncrementalGeneratorInitializationContext context,
IncrementalValueProvider<SourceGeneratorConfiguration> configuration)
{
#if EMBEDDED
context.RegisterPostInitializationOutput(ctx =>
{
ctx.AddEmbeddedAttributeDefinition();
});
#endif
context.RegisterImplementationSourceOutput(configuration, static (ctx, configuration) =>
{
if (configuration.GenerateInterceptorAttribute)
ctx.AddSource("InterceptorAttribute.g.cs", SourceText.From(InterceptorAttributeEmitter.Emit(), Encoding.UTF8));
});
}
}