Replies: 1 comment 7 replies
-
While I'm fine with using source generators to reduce boilerplate, I think it's okay to have some level of reflection if it makes the API easier. Subclass registration is one of those areas where I think reflection does more good than harm, as it makes GObject integration effectively transparent to the user (and one of the biggest benefits of doing Gtk with C# is API cleanliness imo). A particular concern I have about source generators is that they preclude us from ever supporting F#/VB. Microsoft actually advises to only use source generators to optimise rather than replace certain features, and have a reflection based alternative as a fallback:
That being said, I did have an idea for getting around reflection for instance/class init. We could let the user assign the relevant methods in the static constructor, and then retrieve these later without reflection. For example: static MySubclass()
{
SetClassInit(typeof(MySubclass), MyClassInitFunc);
SetInstanceInit(typeof(MySubclass), SomeOtherFunction);
} Which then are stored in some kind of dictionary, hashset, etc (the same way we'd do it using module initialisers). This avoids a hard dependency of source generators and also keeps things within the class. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
In custom GObject subclasses we are interested in different information like
ClassInit
,InstanceInit
static methods.This information could be made available in some kind of
SubclassDescriptor
, simmilar to theTypeDescriptor
as a delegate.If the registration of types is not done via reflection but with some module initializer we can use source generators to register the GObject subclasses during compile time of our users.
We could than use the
SubclassDescriptor
during object creation of a type to retrieve a delegate for theClassInit
method without reflection.Beta Was this translation helpful? Give feedback.
All reactions