From 659baff30ca9a088d4a6dcefed21decedaa9ea78 Mon Sep 17 00:00:00 2001 From: redglow Date: Fri, 17 Jul 2026 10:28:46 +0200 Subject: [PATCH] chore: change to safely access nameof(_serviceScope) --- addons/GodotDI/GodotDI.cs | 5 ++- addons/GodotDI/ScopeInspectorPlugin.cs | 43 ++++++++++++++------------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/addons/GodotDI/GodotDI.cs b/addons/GodotDI/GodotDI.cs index b6235c2..cf20750 100644 --- a/addons/GodotDI/GodotDI.cs +++ b/addons/GodotDI/GodotDI.cs @@ -1,18 +1,17 @@ #if TOOLS using Godot; -using GodotHostTest.addons.godot_di; namespace GodotHostTest.GodotDI; [Tool] public partial class GodotDI : EditorPlugin { - private ScopeInspectorPlugin? _plugin; + private ServiceSource.ScopeInspectorPlugin? _plugin; public override void _EnterTree() { GD.Print("Initializing Godot DI"); - _plugin = new ScopeInspectorPlugin(); + _plugin = new ServiceSource.ScopeInspectorPlugin(); AddInspectorPlugin(_plugin); } diff --git a/addons/GodotDI/ScopeInspectorPlugin.cs b/addons/GodotDI/ScopeInspectorPlugin.cs index f049aea..d8a6b37 100644 --- a/addons/GodotDI/ScopeInspectorPlugin.cs +++ b/addons/GodotDI/ScopeInspectorPlugin.cs @@ -4,28 +4,33 @@ using GodotHostTest.addons.godot_di; namespace GodotHostTest.GodotDI; -public partial class ScopeInspectorPlugin : EditorInspectorPlugin +public partial class ServiceSource { - public override bool _CanHandle(GodotObject @object) + // it's inside ServiceSource so that it can safely access nameof(_serviceScope) + public partial class ScopeInspectorPlugin : EditorInspectorPlugin { - var result = @object.GetScript().AsGodotObject() is CSharpScript script && - GodotScriptPathCache.TryGetTypeFromPath(script.ResourcePath, out var type) && - type.IsAssignableTo(typeof(ServiceSource)); - return result; - } + public override bool _CanHandle(GodotObject @object) + { + var result = @object.GetScript().AsGodotObject() is CSharpScript script && + GodotScriptPathCache.TryGetTypeFromPath(script.ResourcePath, out var type) && + type.IsAssignableTo(typeof(ServiceSource)); + return result; + } - public override bool _ParseProperty(GodotObject @object, Variant.Type type, string name, PropertyHint hintType, - string hintString, - PropertyUsageFlags usageFlags, bool wide) - { - // We handle properties of type integer. - if (name != "_serviceScope") return false; - // Create an instance of the custom property editor and register - // it to a specific property path. - AddPropertyEditor(name, new ScopePickerEditor()); - // Inform the editor to remove the default property editor for - // this property type. - return true; + public override bool _ParseProperty(GodotObject @object, Variant.Type type, string name, PropertyHint hintType, + string hintString, + PropertyUsageFlags usageFlags, bool wide) + { + // We handle properties of type integer. + if (name != nameof(_serviceScope)) return false; + // Create an instance of the custom property editor and register + // it to a specific property path. + AddPropertyEditor(name, new ScopePickerEditor()); + // Inform the editor to remove the default property editor for + // this property type. + return true; + } } } + #endif \ No newline at end of file