C# generalized class-based types

Godot Version

4.2

Question

I have an example that works great.

public partial class DropMenu : Button
{
    private object[] _items;

    public void Init<T>(T startItem ) where T : Enum
    {
        var items = Arithmetic.GetEnumerableEnum<T>().ToArray();
        _items = items.Cast<object>().ToArray();
        _index = Array.IndexOf(items, startItem);
    }
}

example of receiving
GetNode<DropMenu >("....")

But when I use “T” I get an error

public partial class DropMenu<T> : Button where T : Enum
{
    private int _index, _oldIndex;
    private T[] _items = Arithmetic.GetEnumerableEnum<T>().ToArray();

    public void Init(T startItem)
    {
          _index = Array.IndexOf(_items, startItem);
    }
}

I get an error this
GetNode<DropMenu<тSomeEnum>>("....")

question - is there a way to solve this problem? or should I just put up with it and write “shit code”?

object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object): System.InvalidCastException: Unable to cast object of type ‘Godot.Button’ to type ‘DropMenu`1[Mygame.Scripts.GameLogic.World.Base.BaseRoom+ThisType]’.
<Ошибка C++> System.InvalidCastException

I have a few questions:

  1. Why do you want to be able to pass a type to your button?
  2. What else have you tried or thought of that you consider “shit code”?
  1. I have a window. with the choice of characteristics of various objects of the enum type) and I want to make a single class
  2. first, translating from Enum to object and back is not very nice and correct)

it is possible to do this, but how to get the entire interface from getNode tc is ready and you need to set the necessary properties for objects?(