public DynamicMetaObject MakeCallExpression(OverloadResolverFactory resolverFactory, MethodInfo method, params DynamicMetaObject[] parameters) { OverloadResolver resolver; if (method.IsStatic) { resolver = resolverFactory.CreateOverloadResolver(parameters, new CallSignature(parameters.Length), CallTypes.None); } else { resolver = resolverFactory.CreateOverloadResolver(parameters, new CallSignature(parameters.Length - 1), CallTypes.ImplicitInstance); } BindingTarget target = resolver.ResolveOverload(method.Name, new MethodBase[] { method }, NarrowingLevel.None, NarrowingLevel.All); if (!target.Success) { BindingRestrictions restrictions = BindingRestrictions.Combine(parameters); foreach (DynamicMetaObject mo in parameters) { restrictions = restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(mo.Expression, mo.GetLimitType())); } return(DefaultBinder.MakeError( resolver.MakeInvalidParametersError(target), restrictions, typeof(object) )); } return(new DynamicMetaObject(target.MakeExpression(), target.RestrictedArguments.GetAllRestrictions())); }
protected internal override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance) { if (instance != null && IsStatic) { return(null); } if (GetIndexParameters().Length > 0) { // need to bind to a value or parameters to get the value. return(binder.ReturnMemberTracker(type, BindToInstance(instance))); } MethodInfo getter = ResolveGetter(binder.PrivateBinding); if (getter == null || getter.ContainsGenericParameters) { // no usable getter return(null); } if (getter.IsPublic && getter.DeclaringType.IsVisible) { return(binder.MakeCallExpression(context, getter, instance)); } // private binding is just a call to the getter method... return(DefaultBinder.MakeError(((DefaultBinder)binder).MakeNonPublicMemberGetError(context, this, type, instance))); }
protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { if (instance != null && IsStatic) { return(null); } if (GetIndexParameters().Length > 0) { // need to bind to a value or parameters to get the value. return(binder.ReturnMemberTracker(type, BindToInstance(instance))); } MethodInfo getter = GetGetMethod(true); if (getter == null || getter.ContainsGenericParameters) { // no usable getter return(null); } // TODO (tomat): this used to use getter.ReflectedType, is it still correct? getter = CompilerHelpers.TryGetCallableMethod(instance.GetLimitType(), getter); var defaultBinder = (DefaultBinder)binder; if (binder.PrivateBinding || CompilerHelpers.IsVisible(getter)) { return(defaultBinder.MakeCallExpression(resolverFactory, getter, instance)); } // private binding is just a call to the getter method... return(DefaultBinder.MakeError(defaultBinder.MakeNonPublicMemberGetError(resolverFactory, this, type, instance), BindingRestrictions.Empty, typeof(object))); }
protected internal override Expression GetBoundValue(Expression context, ActionBinder binder, Type type, Expression instance) { if (IsPublic && DeclaringType.IsVisible) { return(Ast.Field( Ast.Convert(instance, Field.DeclaringType), Field )); } return(DefaultBinder.MakeError(((DefaultBinder)binder).MakeNonPublicMemberGetError(context, this, type, instance))); }
protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { if (IsPublic && DeclaringType.IsVisible) { return(new DynamicMetaObject( AstUtils.Convert( Expression.Field( AstUtils.Convert(instance.Expression, Field.DeclaringType), Field ), typeof(object) ), BindingRestrictions.Empty )); } return(DefaultBinder.MakeError(((DefaultBinder)binder).MakeNonPublicMemberGetError(resolverFactory, this, type, instance), BindingRestrictions.Empty, typeof(object))); }