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)); }
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)); }