I want to use the Dart/reflectable framework to find all subclasses of a specific base class and I struggle with that use case.
I have
- An abstract base class with a few getters:
abstract class MyBaseClass {
String get name;
List<MyValueType> get values;
}
- Several classes that implement
MyBaseClass
:
class A implements MyBaseClass {
@override
String name = 'AClass';
@override
List<MyValueType> = [MyValueType.X, MyValueType.Y];
}
class B implements MyBaseClass {
@override
String name = 'BClass';
@override
List<MyValueType> = [];
}
My goal is to fetch all classes that implement MyBaseClass
and read their properties.
So, I created:
class Reflector extends Reflectable {
const Reflector()
: super(invokingCapability);
}
const reflector = const Reflector();
- How do I fetch a list of classes? I only found the
InstanceMirror.reflect()
which only delivers one result, not many. - It is not clear, how the annotation must be set. When trying to fetch all
MyBaseClass
implementations, do I need to annotate only my abstractMyBaseClass
or do I need to annotate classesA
andB
or do I need to annotate all three classes? - Which capabilities do I need? In my test case I got this exception:
NoSuchCapabilityError: no capability to invoke the getter "name"
but was not able to solve this.
Thanks in advance, any help is appreciated!
Aucun commentaire:
Enregistrer un commentaire