in Dart, using Mirrors, how would you call a class's static method from an instance of the class? in Dart, using Mirrors, how would you call a class's static method from an instance of the class? dart dart

in Dart, using Mirrors, how would you call a class's static method from an instance of the class?


This should get you started.findStaticAndInvoke() looks at the class of the provided object and it's subclasses for the static method or getter and invokes it when found.

library x;import 'dart:mirrors';abstract class Junk {  static void doSomething() {    print("Junk.doSomething()");  }}class Hamburger extends Junk {  static bool get lettuce => true;}class HotDog extends Junk {  static bool get lettuce => false;}Junk food; // either Hamburger or Hotdogvoid main(List<String> args) {  Junk food = new HotDog();  findStaticAndInvoke(food, "doSomething");  findStaticAndInvoke(food, "lettuce");  food = new Hamburger();  findStaticAndInvoke(food, "doSomething");  findStaticAndInvoke(food, "lettuce");}void findStaticAndInvoke(o, String name) {  ClassMirror r = reflect(o).type;  MethodMirror sFn;  var s = new Symbol(name);  while (sFn == null && r != null) {    sFn = r.staticMembers[s];    if(sFn != null) {      break;    }    r = r.superclass;  }  if(sFn != null) {    if(sFn.isGetter) {      print(r.getField(s).reflectee);    }    else {      r.invoke(s, []);    }  }}