리플렉션을 사용하는 Dart에서 엔티티 관리자를 만들려고합니다. 방법은 getById (String id, String returnClass) 메서드는 _get [returnClass] ById (String id) 메서드를 호출합니다.Reflection : LibraryMirror에 함수가 없습니다.
이렇게하려면 dart : mirrors를 사용하고 있으며 엔티티 관리자 개체에 이러한 메서드가 있는지 확인한 다음 호출 해보십시오. 불행히도 LibraryMirror에는 함수가 없습니다.
class EntityMgr {
Object getById(String id, String returnClass) {
InstanceMirror result = null;
String methodName = '_get'+returnClass+'ById';
// Check if a method '_get[returnClass]Byid exists and call it with given ID
if(_existsFunction(methodName)) {
Symbol symbol = new Symbol(methodName);
List methodParameters = new List();
methodParameters.add(id);
result = currentMirrorSystem().isolate.rootLibrary.invoke(symbol, methodParameters);
}
return result;
}
Product _getProductById(String id) {
return new Product();
}
bool _existsFunction(String functionName) {
return currentMirrorSystem().isolate.rootLibrary.functions.containsKey(functionName);
}
}