Ejemplo n.º 1
0
        protected override Expression BuildCtorExpression(ExpressionBuilderArgs args)
        {
            var elementType = MemberType.GetElementType();
            var lengthVar   = Expression.Variable(typeof(UInt64), "length");
            var ctorExp     = Expression.NewArrayBounds(
                elementType,
                lengthVar);

            return(Expression.Block(new [] { lengthVar },
                                    Expression.Assign(lengthVar, Invoke(_length, args)),
                                    AdvancedExpression.Debug(string.Format("Array {0} initialized. ({{0}} elements).", MemberName), lengthVar),
                                    ctorExp));
        }
Ejemplo n.º 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 elementType = MemberType.GetElementType();

            Expression arrayAccess = BuildArrayAccess(p_obj, p_i2);

            return(Expression.Lambda <Func <object, int, int, T> >(
                       ValueType.IsAssignableFrom(elementType) ?
                       arrayAccess : Expression.Convert(arrayAccess, ValueType),
                       p_obj, p_i1, p_i2
                       ).Compile());
        }
Ejemplo n.º 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        elementType = MemberType.GetElementType();
            Expression param       = p_val;

            var arrayAccess = BuildArrayAccess(p_obj, p_i2);

            return(Expression.Lambda <Action <object, int, int, T> >(
                       Expression.Assign(
                           arrayAccess,
                           elementType.IsAssignableFrom(ValueType) ?
                           param : Expression.Convert(p_val, elementType)
                           ),
                       p_obj, p_i1, p_i2, p_val
                       ).Compile());
        }
Ejemplo n.º 4
0
        protected override Expression BuildBodyExpression(ExpressionBuilderArgs args, ParameterExpression innerResultVar, ParameterExpression typeVar)
        {
            var elementType = MemberType.GetElementType();

            if (elementType == typeof(Byte))
            {
                return(Expression.Call(
                           args.BrParameter,
                           "ReadBits",
                           null,
                           Expression.New(
                               typeof(BinarySize).GetConstructor(new[] { typeof(UInt64), typeof(Byte) }),
                               Invoke(_length, args),
                               Expression.Constant((Byte)0, typeof(Byte))),
                           Expression.Constant(null, typeof(Endianness?))));
            }
            else
            {
                return(base.BuildBodyExpression(args, innerResultVar, typeVar));
            }
        }
Ejemplo n.º 5
0
 public ArrayMember(string name, Type type)
     : base(name, type)
 {
     _elementType = MemberType.GetElementType();
     _newLength   = -1;
 }