add: LoadingScene, ProxyNode
This commit is contained in:
33
src/Generators/RegistryEntityGenerator.cs
Normal file
33
src/Generators/RegistryEntityGenerator.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Polonium.Generators.Generators;
|
||||
[Generator]
|
||||
public class RegistryEntityGenerator : AssetProcessGenerator
|
||||
{
|
||||
public override void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
if (!(context.SyntaxReceiver is ClassSyntaxReceiver receiver))
|
||||
return;
|
||||
Compilation compilation = context.Compilation;
|
||||
INamedTypeSymbol? regEntity = compilation.GetTypeByMetadataName("Polonium.Attributes.RegistryEntity");
|
||||
foreach (var derivedClassDeclaration in receiver.Classes)
|
||||
{
|
||||
SemanticModel model = compilation.GetSemanticModel(derivedClassDeclaration.SyntaxTree);
|
||||
if (
|
||||
model.GetDeclaredSymbol(derivedClassDeclaration) is INamedTypeSymbol symbol &&
|
||||
symbol.GetAttributes().Any(x => SymbolEqualityComparer.Default.Equals(x.AttributeClass, regEntity))
|
||||
)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb
|
||||
.AppendLine("public static partial class GlobalRegistry")
|
||||
.AppendLine("{")
|
||||
.AppendLine($" public static {symbol.ToDisplayString()} {symbol.Name} {{ get; set; }} ")
|
||||
.AppendLine("}");
|
||||
context.AddSource($"RegistryEntity_{symbol.Name}.g.cs", sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user