Exemplo n.º 1
0
        public Expression <Func <object[], T> > CreateFromMethod()
        {
            var objectArray        = Expression.Parameter(typeof(object[]), "item");
            var item               = Expression.Variable(Type);
            List <Expression> list = new List <Expression>();

            if (!DataType.IsPrimitiveType(Type))
            {
                list.Add(Expression.Assign(item, Expression.New(item.Type.GetConstructor(new Type[] { }))));
            }

            list.Add(ValueToObjectsHelper.FromObjects(item, objectArray, MembersOrder));
            list.Add(Expression.Label(Expression.Label(typeof(T)), item));

            var body = Expression.Block(typeof(T), new ParameterExpression[] { item }, list);

            return(Expression.Lambda <Func <object[], T> >(body, objectArray));
        }
Exemplo n.º 2
0
        public Expression <Func <object[], IData> > CreateFromMethod()
        {
            var objectArray = Expression.Parameter(typeof(object[]), "item");
            var data        = Expression.Variable(typeof(Data <>).MakeGenericType(Type));

            List <Expression> list = new List <Expression>();

            list.Add(Expression.Assign(data, Expression.New(data.Type.GetConstructor(new Type[] { }))));

            if (!DataType.IsPrimitiveType(Type))
            {
                list.Add(Expression.Assign(data.Value(), Expression.New(data.Value().Type.GetConstructor(new Type[] { }))));
            }

            list.Add(ValueToObjectsHelper.FromObjects(data.Value(), objectArray, MembersOrder));
            list.Add(Expression.Label(Expression.Label(typeof(IData)), data));

            var body = Expression.Block(typeof(IData), new ParameterExpression[] { data }, list);

            return(Expression.Lambda <Func <object[], IData> >(body, objectArray));
        }
Exemplo n.º 3
0
        public Expression <Func <IData, object[]> > CreateToMethod()
        {
            var data = Expression.Parameter(typeof(IData), "data");

            var d    = Expression.Variable(typeof(Data <>).MakeGenericType(Type), "d");
            var body = Expression.Block(new ParameterExpression[] { d }, Expression.Assign(d, Expression.Convert(data, d.Type)), ValueToObjectsHelper.ToObjects(d.Value(), MembersOrder));

            return(Expression.Lambda <Func <IData, object[]> >(body, data));
        }
Exemplo n.º 4
0
        public Expression <Func <T, object[]> > CreateToMethod()
        {
            var item = Expression.Parameter(Type);

            return(Expression.Lambda <Func <T, object[]> >(ValueToObjectsHelper.ToObjects(item, MembersOrder), item));
        }