-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathPropertySelectorGenerator.cs
47 lines (41 loc) · 1.72 KB
/
PropertySelectorGenerator.cs
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
45
46
47
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Uno.Extensions.Generators.PropertySelector;
namespace Uno.Extensions.Core.Generators;
/// <summary>
/// A generator that generates IKeyEquatable implementation.
/// </summary>
[Generator]
public partial class PropertySelectorGenerator : IIncrementalGenerator
{
private readonly PropertySelectorsGenerationTool _tool;
/// <summary>
/// Creates a new instance of the PropertySelectorGenerator
/// </summary>
public PropertySelectorGenerator()
{
_tool = new PropertySelectorsGenerationTool();
}
/// <inheritdoc />
public void Initialize(IncrementalGeneratorInitializationContext context)
{
#if DEBUGGING_GENERATOR
var process = Process.GetCurrentProcess().ProcessName;
if (process.IndexOf("VBCSCompiler", StringComparison.OrdinalIgnoreCase) is not -1
|| process.IndexOf("csc", StringComparison.OrdinalIgnoreCase) is not -1)
{
Debugger.Launch();
}
#endif
var assemblyNameProvider = context.CompilationProvider.Select((compilation, _) => compilation.AssemblyName);
var syntaxProvider = context.SyntaxProvider
.CreateSyntaxProvider(
(node, ct) => node.IsKind(SyntaxKind.InvocationExpression),
(ctx, ct) => new PropertySelectorCandidate(ctx, ct))
.Where(candidate => candidate.IsValid).WithTrackingName("syntaxProvider_PropertySelectorGenerator");
var provider = syntaxProvider.Combine(assemblyNameProvider).WithTrackingName("combinedProvider_PropertySelectorGenerator");
// We use the Implementation as the generated code does not alter the SemanticModel (only generates a registry).
context.RegisterImplementationSourceOutput(provider, (context, souce) => _tool.Generate(context, souce.Left, souce.Right));
}
}