示例#1
0
        public static TProxy Set <TProxy, TValue>(this TProxy proxy, Expression <Func <TProxy, TValue> > property, TValue value)
        {
            // get property to assign
            var propExpression = property.Body.Unwrap() as MemberExpression;

            if (propExpression == null || !(propExpression.Member is PropertyInfo))
            {
                throw new ArgumentException("Expecting a property");
            }
            var prop = propExpression.Member as PropertyInfo;

            // check that given proxy is really a proxy
            var p = proxy as IProxy;

            if (p == null)
            {
                throw new NullReferenceException("Cannot set property " + prop.Name + ". Given object is not a proxy.");
            }

            // set the property
            SetCache <TProxy, TValue> .Setter(prop)(proxy, value);

            return(proxy);
        }