internal override DynamicMetaObject Call(OverloadResolverFactory resolverFactory, ActionBinder binder, params DynamicMetaObject[] arguments) {
if (Method.IsPublic && Method.DeclaringType.IsVisible) {
return binder.MakeCallExpression(resolverFactory, Method, arguments);
}
//methodInfo.Invoke(obj, object[] params)
if (Method.IsStatic) {
return new DynamicMetaObject(
Ast.Convert(
Ast.Call(
AstUtils.Constant(Method),
typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
AstUtils.Constant(null),
AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(arguments, x => x.Expression))
),
Method.ReturnType
),
BindingRestrictions.Empty
)
;
}
if (arguments.Length == 0) throw Error.NoInstanceForCall();
return new DynamicMetaObject(
Ast.Convert(
Ast.Call(
AstUtils.Constant(Method),
typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
arguments[0].Expression,
AstUtils.NewArrayHelper(typeof(object), ArrayUtils.ConvertAll(ArrayUtils.RemoveFirst(arguments), x => x.Expression))
),
Method.ReturnType
),
BindingRestrictions.Empty
);
}
}