示例#1
0
        public static TRet As <TRet>(this Object t, Expression <Func <TRet, object> > expr, object val)
        {
            var memberAccess = new ExpressionWithMemberAccess <TRet, object>();

            memberAccess.Lambda(expr);
            var propertyName   = memberAccess.MemberName;
            var createInstance = new CreateInstanceFromValues <TRet>(t.GetType());

            return(createInstance.Create(t, new[] { new NameAndValue(propertyName, val) }));
        }
示例#2
0
        public static T With <T, TVal>(this T t, Expression <Func <T, TVal> > expr, TVal val)
        {
            var memberAccess = new ExpressionWithMemberAccess <T, TVal>();

            memberAccess.Lambda(expr);
            var propertyName = memberAccess.MemberName;

            var createInstance = new CreateInstanceFromValues <T> ();

            return(createInstance.Create(t, new[] { NameAndValues.Create(propertyName, val) }));
        }