Exemple #1
0
        public Expression <Func <IData, string> > CreateToMethod()
        {
            var data = Expression.Parameter(typeof(IData), "data");
            var d    = Expression.Variable(typeof(Data <>).MakeGenericType(Type), "d");

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

            list.Add(Expression.Assign(d, Expression.Convert(data, typeof(Data <>).MakeGenericType(Type))));
            list.Add(ValueToStringHelper.CreateToStringBody(d.Value(), StringBuilderCapacity, Providers, Delimiters[0], MembersOrder));

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

            return(Expression.Lambda <Func <IData, string> >(body, data));
        }
Exemple #2
0
        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 }));
        }
Exemple #3
0
        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 }));
        }
Exemple #4
0
        public Expression <Func <T, string> > CreateToMethod()
        {
            var item = Expression.Parameter(typeof(T));

            return(Expression.Lambda <Func <T, string> >(ValueToStringHelper.CreateToStringBody(item, StringBuilderCapacity, Providers, Delimiters[0], MembersOrder), new ParameterExpression[] { item }));
        }
Exemple #5
0
 public ValueToString(int stringBuilderCapacity, char[] delimiters, Func <Type, MemberInfo, int> membersOrder = null)
     : this(stringBuilderCapacity, ValueToStringHelper.GetDefaultProviders(typeof(T), membersOrder), delimiters, membersOrder)
 {
 }