2012-12-21 35 views

cevap

6

Sen mirrors API ile yapabilirsiniz:

import 'dart:mirrors'; 

class Test { 
    method1() => "hello"; 
} 

main() { 
    print(existsFunction("main")); // true 
    print(existsFunction("main1")); // false 
    print(existsMethodOnObject(new Test(), "method1")); // true 
    print(existsMethodOnObject(new Test(), "method2")); // false 
} 

bool existsFunction(String functionName) => currentMirrorSystem().isolate 
    .rootLibrary.functions.containsKey(functionName); 

bool existsMethodOnObject(Object o, String method) => reflect(o).type.methods 
    .containsKey(method); 

existsFunction sadece testler functionName bir işlev akım kütüphanede varsa. Böylece importexistsFunction bildirimi false tarafından döndürülebilir.

İlgili konular