Beispiel #1
0
            } // ctor

            public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
            {
                // defer the target
                if (!target.HasValue)
                {
                    return(Defer(target));
                }

                if (target.Value == null)
                {
                    return(errorSuggestion ??
                           new DynamicMetaObject(
                               ThrowExpression(String.Format(Resources.rsMemberNotResolved, target.LimitType.Name, Name), 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.TrySetMember(target.Expression, target.LimitType, Name, IgnoreCase,
                                                 (setType) => LuaEmit.ConvertWithRuntime(Lua, value.Expression, value.LimitType, setType),
                                                 out expr))
                    {
                    case LuaTrySetMemberReturn.None:
                        return(errorSuggestion ?? new DynamicMetaObject(ThrowExpression(LuaEmitException.GetMessageText(LuaEmitException.MemberNotFound, target.LimitType.Name, Name), ReturnType), restrictions));

                    case LuaTrySetMemberReturn.NotWritable:
                        return(errorSuggestion ?? new DynamicMetaObject(ThrowExpression(LuaEmitException.GetMessageText(LuaEmitException.CanNotWriteMember, target.LimitType.Name, Name), ReturnType), restrictions));

                    case LuaTrySetMemberReturn.ValidExpression:
                        return(new DynamicMetaObject(Lua.EnsureType(expr, ReturnType), restrictions.Merge(Lua.GetSimpleRestriction(value))));

                    default:
                        throw new ArgumentException("return of TryGetMember.");
                    }
                }
            } // func FallbackSetMember