コード例 #1
0
        private Expression <Func <object[], T> > CreateFromObjectsMethod()
        {
            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(ObjectsHelper.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));
        }
コード例 #2
0
        private Expression <Func <object[], IData> > CreateFromObjectsMethod()
        {
            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(ObjectsHelper.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));
        }
コード例 #3
0
        private Expression <Func <IData, object[]> > CreateToObjectsMethod()
        {
            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)), ObjectsHelper.ToObjects(d.Value(), MembersOrder));

            return(Expression.Lambda <Func <IData, object[]> >(body, data));
        }
コード例 #4
0
        private Expression <Func <T, object[]> > CreateToObjectsMethod()
        {
            var item = Expression.Parameter(Type);

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