-
Notifications
You must be signed in to change notification settings - Fork 0
/
SourceGenerator.cs
72 lines (66 loc) · 2.58 KB
/
SourceGenerator.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Devise.Generators.Api;
using Devise.Generators.Data;
using Devise.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Devise
{
[Generator]
public class SourceGenerator : ISourceGenerator
{
public void Initialize(GeneratorInitializationContext context)
{
#if DEBUG
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
#endif
//context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
}
public void Execute(GeneratorExecutionContext context)
{
// retrieve the populated receiver
//if (!(context.SyntaxContextReceiver is SyntaxReceiver receiver))
// return;
// Load Config
DeviseConfig config = DeviseConfig.LoadConfig(context);
switch(config.ProjectType)
{
case DeviseProjectType.Data:
DeviseAttributeGenerator.Generate(context);
DeviseCustomAttributeGenerator.Generate(context);
//EnumGenerator.Generate(context);
break;
case DeviseProjectType.Business:
break;
case DeviseProjectType.Api:
IEnumerable<ClassDeclarationSyntax> devisableEntities = ProjectLoader.LoadDataProject(config);
DtoGenerator.GenerateCottle(context, config, devisableEntities);
MappingProfileGenerator.GenerateCottle(context, config, devisableEntities);
ControllerGenerator.GenerateCottle(context, config, devisableEntities);
break;
}
}
/// <summary>
/// Created on demand before each generation pass
/// </summary>
//class SyntaxReceiver : ISyntaxContextReceiver
//{
// public List<IGrouping<INamedTypeSymbol, IPropertySymbol>> DevisableEntities = new();
//
// /// <summary>
// /// Called for every syntax node in the compilation, we can inspect the nodes and save any information useful for generation
// /// </summary>
// public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
// {
// IGrouping<INamedTypeSymbol, IPropertySymbol> entity = SyntaxParser.GetDevisableEntityDetails(context);
// if (entity is not null)
// DevisableEntities.Add(entity);
// }
//}
}
}