from method

Iterable<DeclarationMirror>? from(
  1. dynamic instance
)

Get List of variables annotated with T from the InstanceMirror instance. For example:

class ObjectWithAnnotatedAttr {

  @Annotation1()
  @Annotation2()
  var annotated1

  @Annotation1()
  var annotated2
}

main() {
  var o = new ObjectWithAnnotatedAttr();

  // should return a list of [VariableMirror] of annotated1 and annotated2
  var variablesAnnotatedWithAnnotation1 = new GetFieldsAnnotatedWith<Annotation1>().from(o);

  // should return a list of [VariableMirror] of annotated1
  var fieldsAnnotatedWithAnnotation2 = new GetFieldsAnnotatedWith<Annotation2>().from(o);
}

Implementation

Iterable<DeclarationMirror>? from(instance) => reflect(instance)
    ?.fields
    ?.values
    .where((methodMirror) => methodMirror.annotations?.any(Is<T>()) == true);