コード例 #1
0
        protected override Func <object, int, int, bool> BuildCheckIndex()
        {
            var p_obj = Expression.Parameter(typeof(object));
            var p_i1  = Expression.Parameter(typeof(int));
            var p_i2  = Expression.Parameter(typeof(int));

            Expression access     = Expression.MakeMemberAccess(Expression.Convert(p_obj, ObjectType), MemberInfo);
            Expression checkindex = Expression.Call(access, MemberType.GetMethod("CheckIndex"), p_i1, p_i2);

            return(Expression.Lambda <Func <object, int, int, bool> >(checkindex, p_obj, p_i1, p_i2).Compile());
        }
コード例 #2
0
        protected override Func <object, int, int, T> BuildGetter()
        {
            var p_obj   = Expression.Parameter(typeof(object));
            var p_i1    = Expression.Parameter(typeof(int));
            var p_i2    = Expression.Parameter(typeof(int));
            var valType = GetValueType();

            Expression access = Expression.MakeMemberAccess(Expression.Convert(p_obj, ObjectType), MemberInfo);
            Expression getter = Expression.Call(access, MemberType.GetMethod("Get"), p_i1, p_i2);

            return(Expression.Lambda <Func <object, int, int, T> >(
                       ValueType.IsAssignableFrom(valType) ?
                       getter : Expression.Convert(getter, ValueType),
                       p_obj, p_i1, p_i2
                       ).Compile());
        }
コード例 #3
0
        protected override Action <object, int, int, T> BuildSetter()
        {
            var        p_obj   = Expression.Parameter(typeof(object));
            var        p_i1    = Expression.Parameter(typeof(int));
            var        p_i2    = Expression.Parameter(typeof(int));
            var        p_val   = Expression.Parameter(ValueType);
            var        valType = GetValueType();
            Expression param   = p_val;

            Expression access = Expression.MakeMemberAccess(Expression.Convert(p_obj, ObjectType), MemberInfo);
            Expression val    = valType.IsAssignableFrom(ValueType) ?
                                param : Expression.Convert(p_val, valType);
            Expression setter = Expression.Call(access, MemberType.GetMethod("Set"), p_i1, p_i2, val);

            return(Expression.Lambda <Action <object, int, int, T> >(setter,
                                                                     p_obj, p_i1, p_i2, p_val
                                                                     ).Compile());
        }