chore: change to safely access nameof(_serviceScope)

This commit is contained in:
redglow
2026-07-17 10:28:46 +02:00
parent 90f227d794
commit 659baff30c
2 changed files with 26 additions and 22 deletions
+2 -3
View File
@@ -1,18 +1,17 @@
#if TOOLS #if TOOLS
using Godot; using Godot;
using GodotHostTest.addons.godot_di;
namespace GodotHostTest.GodotDI; namespace GodotHostTest.GodotDI;
[Tool] [Tool]
public partial class GodotDI : EditorPlugin public partial class GodotDI : EditorPlugin
{ {
private ScopeInspectorPlugin? _plugin; private ServiceSource.ScopeInspectorPlugin? _plugin;
public override void _EnterTree() public override void _EnterTree()
{ {
GD.Print("Initializing Godot DI"); GD.Print("Initializing Godot DI");
_plugin = new ScopeInspectorPlugin(); _plugin = new ServiceSource.ScopeInspectorPlugin();
AddInspectorPlugin(_plugin); AddInspectorPlugin(_plugin);
} }
+24 -19
View File
@@ -4,28 +4,33 @@ using GodotHostTest.addons.godot_di;
namespace GodotHostTest.GodotDI; 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 && public override bool _CanHandle(GodotObject @object)
GodotScriptPathCache.TryGetTypeFromPath(script.ResourcePath, out var type) && {
type.IsAssignableTo(typeof(ServiceSource)); var result = @object.GetScript().AsGodotObject() is CSharpScript script &&
return result; 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, public override bool _ParseProperty(GodotObject @object, Variant.Type type, string name, PropertyHint hintType,
string hintString, string hintString,
PropertyUsageFlags usageFlags, bool wide) PropertyUsageFlags usageFlags, bool wide)
{ {
// We handle properties of type integer. // We handle properties of type integer.
if (name != "_serviceScope") return false; if (name != nameof(_serviceScope)) return false;
// Create an instance of the custom property editor and register // Create an instance of the custom property editor and register
// it to a specific property path. // it to a specific property path.
AddPropertyEditor(name, new ScopePickerEditor()); AddPropertyEditor(name, new ScopePickerEditor());
// Inform the editor to remove the default property editor for // Inform the editor to remove the default property editor for
// this property type. // this property type.
return true; return true;
}
} }
} }
#endif #endif