Reflectable class Null safety

Reflectable is used as metadata, marking classes for reflection.

If a class has an instance of a subclass of this class in its metadata1 then it will be included in the root set of classes with support for reflection based on this package. Other classes outside the root set may also be included, e.g., if it is specified that all subtypes of a given class in the root set are included. For classes and instances not included, all reflective operations will throw an exception. For included classes and instances, invocations of the operations in mirrors.dart are supported if the ReflectCapability values given as constructor arguments include the capability to run those operations; the operations will throw an exception if the relevant capability is not included.

Terminology: We use the term reflector class to denote a direct subclass of Reflectable with a zero-argument const constructor that is used as metadata on a class in the target program in one of the two supported manners: as a const constructor expression (@MyReflectable()), or as an identifier (@myReflectable) which is a top-level const whose value is an instance of the given reflector class (const myReflectable = const MyReflectable();). We use the term reflector-annotated class to denote a class whose metadata includes an instance of a reflector class.

Note that the role played by this class includes much of the role played by a MirrorSystem with dart:mirrors.


  1. Currently, the only setup which is supported is when the metadata object is an instance of a direct subclass of the class Reflectable, say MyReflectable, and that subclass defines a const constructor taking zero arguments. This ensures that every subclass of Reflectable used as metadata is a singleton class, which means that the behavior of the instance can be expressed by generating code in the class. Generalizations of this setup may be supported in the future if compelling use cases come up.
Implemented types


Reflectable([ReflectCapability? cap0, ReflectCapability? cap1, ReflectCapability? cap2, ReflectCapability? cap3, ReflectCapability? cap4, ReflectCapability? cap5, ReflectCapability? cap6, ReflectCapability? cap7, ReflectCapability? cap8, ReflectCapability? cap9])
Const constructor, to enable usage as metadata, allowing for varargs style invocation with up to ten arguments.
Reflectable.fromList(List<ReflectCapability> capabilities)


annotatedClasses Iterable<ClassMirror>
Returns an Iterable of all the classes that can be reflected over in this Reflectable.
read-only, inherited
capabilities List<ReflectCapability>
Specifies limits on the support for reflective operations on instances of classes having an instance of this ReflectableBase as metadata.
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
libraries Map<Uri, LibraryMirror>
Returns a map of all libraries in the current isolate.
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


canReflect(Object reflectee) bool
Returns true if this reflector has capabilities for the given instance.
canReflectType(Type type) bool
Returns true if this reflector has capabilities for the given Type.
findLibrary(String libraryName) LibraryMirror
Returns a mirror of the given library library.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
reflect(Object reflectee) InstanceMirror
Returns a mirror of the given object reflectee. [...]
reflectType(Type type) TypeMirror
Returns a mirror of the given type type. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]

Static Methods

getInstance(Type type) Reflectable?
Returns the canonicalized instance of the given reflector type. [...]


thisClassId → const String
thisClassName → const String