invokeByMirror static method

dynamic invokeByMirror(
  1. ObjectMirror instance,
  2. MethodMirror method,
  3. List params, [
  4. Map<String, dynamic>? namedArgs,
])

Invoke a method of the specified ObjectMirror.

  • instance - the ObjectMirror.
  • method - the method.
  • params - the positional + optional parameters.
  • namedArgs - the optional named arguments. Ignored if the method is a getter or setter.

Implementation

static invokeByMirror(ObjectMirror instance, MethodMirror method,
    List params, [Map<String, dynamic>? namedArgs]) {
  InstanceMirror result;
  if (method.isGetter) {
    result = instance.getField(method.simpleName);
  } else if (method.isSetter) {
    result = instance.setField(method.simpleName, params[0]);
  } else {
    result = instance.invoke(method.simpleName, params, _toNamedParams(namedArgs) ?? const <Symbol, dynamic>{});
  }
  return result.reflectee;
}