} // func MemberGetSandbox private static Expression MemberGetExpressionCore(Lua lua, Token tokenStart, Expression instance, string memberName) { // if this is a dynamic type, let the type deside what is to do if (LuaEmit.IsDynamicType(instance.Type)) { return(DynamicExpression.Dynamic(lua.GetGetMemberBinder(memberName), typeof(object), ConvertObjectExpression(lua, tokenStart, instance, true))); } else { Expression result; switch (LuaEmit.TryGetMember(instance, instance.Type, memberName, false, out result)) { case LuaTryGetMemberReturn.None: throw ParseError(tokenStart, LuaEmitException.GetMessageText(LuaEmitException.MemberNotFound, instance.Type.Name, memberName)); case LuaTryGetMemberReturn.NotReadable: throw ParseError(tokenStart, LuaEmitException.GetMessageText(LuaEmitException.CanNotReadMember, instance.Type.Name, memberName)); case LuaTryGetMemberReturn.ValidExpression: return(result); default: throw new ArgumentException("Internal return type of TryGetMember"); } } } // func MemberGetExpressionCore
} // ctor public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { // defer the target, to get the type if (!target.HasValue) { return(Defer(target)); } if (target.Value == null) // no value for target, finish binding with an error or the suggestion { return(errorSuggestion ?? new DynamicMetaObject( ThrowExpression(Resources.rsNullReference, ReturnType), target.Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(target.Expression, null)) )); } else { Expression expr; // restrictions var restrictions = target.Restrictions.Merge(BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType)); // try to bind the member switch (LuaEmit.TryGetMember(target.Expression, target.LimitType, Name, IgnoreCase, out expr)) { case LuaTryGetMemberReturn.None: return(errorSuggestion ?? new DynamicMetaObject(Expression.Default(ReturnType), restrictions)); case LuaTryGetMemberReturn.NotReadable: return(errorSuggestion ?? new DynamicMetaObject(ThrowExpression(LuaEmitException.GetMessageText(LuaEmitException.CanNotReadMember, target.LimitType.Name, Name), ReturnType), restrictions)); case LuaTryGetMemberReturn.ValidExpression: return(new DynamicMetaObject(Lua.EnsureType(expr, ReturnType), restrictions)); default: throw new ArgumentException("return of TryGetMember."); } } } // func FallbackGetMember