Closed MikeMitterer closed 8 years ago
I'd like to. But I am swamped with work at the moment.
From memory all of the mirrors lives in renderer.dart. See: Renderer._getNamedProperty().
Credit to Michael Hixson who implemented the mirrors code.
// Returns the property of the given object by name. For a map,
// which contains the key name, this is object[name]. For other
// objects, this is object.name or object.name(). If no property
// by the given name exists, this method returns noSuchProperty.
_getNamedProperty(object, name) {
if (object is Map && object.containsKey(name)) return object[name];
if (object is List && _integerTag.hasMatch(name)) return object[
int.parse(name)];
if (lenient && !_validTag.hasMatch(name)) return noSuchProperty;
var instance = reflect(object);
var field = instance.type.instanceMembers[new Symbol(name)];
if (field == null) return noSuchProperty;
var invocation = null;
if ((field is VariableMirror) ||
((field is MethodMirror) && (field.isGetter))) {
invocation = instance.getField(field.simpleName);
} else if ((field is MethodMirror) && (field.parameters.length == 0)) {
invocation = instance.invoke(field.simpleName, []);
}
if (invocation == null) {
return noSuchProperty;
}
return invocation.reflectee;
}
Hi, you saw my PR?
Thanks for the PR. Sorry about being slow to merge. I have a lot on my plate. I'm hoping to sort out PRs in my projects during the next week or two.
Thanks
https://pub.dartlang.org/packages/reflectable