public Expression <Func <string, T> > CreateFromMethod() { var stringParam = Expression.Parameter(typeof(string), "item"); List <Expression> list = new List <Expression>(); var item = Expression.Variable(Type); if (!DataType.IsPrimitiveType(Type)) { list.Add(Expression.Assign(item, Expression.New(Type.GetConstructor(new Type[] { })))); } list.Add(ValueToStringHelper.CreateParseBody(item, stringParam, Providers, Delimiters, MembersOrder)); list.Add(Expression.Label(Expression.Label(Type), item)); var body = Expression.Block(new ParameterExpression[] { item }, list); return(Expression.Lambda <Func <string, T> >(body, new ParameterExpression[] { stringParam })); }
public Expression <Func <string, IData> > CreateFromMethod() { var stringParam = Expression.Parameter(typeof(string), "item"); List <Expression> list = new List <Expression>(); var data = Expression.Variable(typeof(Data <>).MakeGenericType(Type), "d"); list.Add(Expression.Assign(data, Expression.New(data.Type.GetConstructor(new Type[] { })))); if (!DataType.IsPrimitiveType(Type)) { list.Add(Expression.Assign(data.Value(), Expression.New(Type.GetConstructor(new Type[] { })))); } list.Add(ValueToStringHelper.CreateParseBody(data.Value(), stringParam, Providers, Delimiters, MembersOrder)); list.Add(Expression.Label(Expression.Label(typeof(Data <>).MakeGenericType(Type)), data)); var body = Expression.Block(new ParameterExpression[] { data }, list); return(Expression.Lambda <Func <string, IData> >(body, new ParameterExpression[] { stringParam })); }