diff --git a/Generators/NodeBindGenerator.cs b/Generators/NodeBindGenerator.cs
index 89a7c58..8c8a9f6 100644
--- a/Generators/NodeBindGenerator.cs
+++ b/Generators/NodeBindGenerator.cs
@@ -12,21 +12,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
public class NodeBindGenerator : IIncrementalGenerator
{
- private const string AttributeSourceCode = """
- //
- namespace Godot.Sharp.Extended.Generators;
-
- [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
- public class NodeBindAttribute : Attribute
- {
- }
- """;
public void Initialize(IncrementalGeneratorInitializationContext context)
{
- context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
- "NodeBindAttribute.g.cs",
- SourceText.From(AttributeSourceCode, Encoding.UTF8)));
-
var propertyProvider = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: (s, _) => s is ClassDeclarationSyntax,
@@ -60,7 +47,7 @@ public class NodeBindGenerator : IIncrementalGenerator
continue;
var attributeName = symbol.ContainingType.ToDisplayString();
- if (attributeName == $"Godot.Sharp.Extended.Generators.NodeBind")
+ if (attributeName == $"Godot.Sharp.Extended.Attributes.NodeBind")
return declarationSyntax;
}
diff --git a/Generators/NodePropBindGenerator.cs b/Generators/NodePropBindGenerator.cs
index 681f9cb..603cb98 100644
--- a/Generators/NodePropBindGenerator.cs
+++ b/Generators/NodePropBindGenerator.cs
@@ -13,28 +13,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
public class NodePropBindGenerator : IIncrementalGenerator
{
- private const string AttributeSourceCode = """
- //
- namespace Godot.Sharp.Extended.Generators;
-
- [System.AttributeUsage(System.AttributeTargets.Member)]
- public class NodePropBindAttribute : System.Attribute
- {
- public string TargetNodeName { get; private set; }
- public string GodotPropertyName { get; private set; }
-
- public NodePropBindAttribute(string targetNodeName, string godotPropertyName)
- {
- TargetNodeName = targetNodeName;
- GodotPropertyName = godotPropertyName;
- }
- }
- """;
public void Initialize(IncrementalGeneratorInitializationContext context)
{
- context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
- "NodePropBind.g.cs",
- SourceText.From(AttributeSourceCode, Encoding.UTF8)));
var propertyProvider = context.SyntaxProvider
.CreateSyntaxProvider(
@@ -69,7 +49,7 @@ public class NodePropBindGenerator : IIncrementalGenerator
continue;
var attributeName = symbol.ContainingType.ToDisplayString();
- if (attributeName == "Godot.Sharp.Extended.Generators.NodePropBind")
+ if (attributeName == "Godot.Sharp.Extended.Attributes.NodePropBind")
return declarationSyntax;
}
@@ -132,7 +112,11 @@ public class NodePropBindGenerator : IIncrementalGenerator
propCode.AppendLine($$"""
public {{memberDefinition.Type}} {{propName}}
{
- get => {{memberDefinition.Name}};
+ get {
+ if ({{memberDefinition.NodeProp}} == null)
+ return {{memberDefinition.Name}};
+ return {{memberDefinition.NodeProp}}.{{godotProp}};
+ }
set {
{{memberDefinition.Name}} = value;
if ({{memberDefinition.NodeProp}} != null)
diff --git a/Generators/ResourceGenerator.cs b/Generators/ResourceGenerator.cs
index 1a458f1..a612221 100644
--- a/Generators/ResourceGenerator.cs
+++ b/Generators/ResourceGenerator.cs
@@ -14,25 +14,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
public class ResourceGenerator : IIncrementalGenerator
{
- private const string AttributeSourceCode = """
- //
- namespace Godot.Sharp.Extended.Generators;
-
- [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
- public class ResourcePathAttribute : System.Attribute
- {
- public string Path { get; private set; }
-
- public ResourcePathAttribute(string path) {
- Path = path;
- }
- }
- """;
public void Initialize(IncrementalGeneratorInitializationContext context)
{
- context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
- "ResourcePathAttribute.g.cs",
- SourceText.From(AttributeSourceCode, Encoding.UTF8)));
var classPaths = context.SyntaxProvider
.CreateSyntaxProvider(
@@ -82,7 +65,7 @@ public class ResourceGenerator : IIncrementalGenerator
{
var symbolInfo = ctx.SemanticModel.GetSymbolInfo(attributeSyntax);
if (symbolInfo.Symbol is not IMethodSymbol attributeSymbol) continue;
- if (attributeSymbol.ContainingType.ToDisplayString() != "Godot.Sharp.Extended.Generators.ResourcePath") continue;
+ if (attributeSymbol.ContainingType.ToDisplayString() != "Godot.Sharp.Extended.Attributes.ResourcePath") continue;
var parameter = attributeSyntax.ArgumentList;
var pathArgument = parameter?.Arguments[0];