public void SetValue()
		{
			var accessor = PropertyAccessorFactory.GetPropertyAccessor("backfield");
			var getter = accessor.GetGetter(typeof(MyAutoProp), "AutoProp");
			var setter = accessor.GetSetter(typeof(MyAutoProp), "AutoProp");

			var rogetter = accessor.GetGetter(typeof(MyAutoProp), "ReadOnlyAutoProp");
			var rosetter = accessor.GetSetter(typeof(MyAutoProp), "ReadOnlyAutoProp");

			var i = new MyAutoProp { AutoProp = -1 };
			Assert.That(getter.Get(i), Is.EqualTo(-1));
			setter.Set(i, 5);
			Assert.That(getter.Get(i), Is.EqualTo(5));

			Assert.That(rogetter.Get(new MyAutoProp()), Is.EqualTo(0));
			rosetter.Set(i, 123);
			Assert.That(rogetter.Get(i), Is.EqualTo(123));
		}
예제 #2
0
        public void SetValue()
        {
            var accessor = PropertyAccessorFactory.GetPropertyAccessor("backfield");
            var getter   = accessor.GetGetter(typeof(MyAutoProp), "AutoProp");
            var setter   = accessor.GetSetter(typeof(MyAutoProp), "AutoProp");

            var rogetter = accessor.GetGetter(typeof(MyAutoProp), "ReadOnlyAutoProp");
            var rosetter = accessor.GetSetter(typeof(MyAutoProp), "ReadOnlyAutoProp");

            var i = new MyAutoProp {
                AutoProp = -1
            };

            Assert.That(getter.Get(i), Is.EqualTo(-1));
            setter.Set(i, 5);
            Assert.That(getter.Get(i), Is.EqualTo(5));

            Assert.That(rogetter.Get(new MyAutoProp()), Is.EqualTo(0));
            rosetter.Set(i, 123);
            Assert.That(rogetter.Get(i), Is.EqualTo(123));
        }