Пример #1
0
        public void TestInstanceWithLambdas()
        {
            MyClass myClass = new MyClass("myClass", 5);
            BoundPropertyDescriptor test;
            
            test = new BoundPropertyDescriptor(myClass, () => myClass.Property, "Property", "", "");
            Assert.IsFalse(test.IsReadOnly);
            Assert.IsTrue(test.GetValue(null).Equals("myClass"));
            test.SetValue(null, "xxx");
            Assert.IsTrue(test.GetValue(null).Equals("xxx"));
            Assert.IsTrue(myClass.Property == "xxx");

            test = new BoundPropertyDescriptor(myClass, () => myClass.ReadOnlyProperty, "ReadOnlyProperty", "", "");
            Assert.IsTrue(test.IsReadOnly);
            Assert.IsTrue(test.GetValue(null).Equals(5));
            test.SetValue(null, 10);
            Assert.IsTrue(test.GetValue(null).Equals(10));
            Assert.IsTrue(myClass.ReadOnlyProperty == 10);
        }
Пример #2
0
        public void TestStaticTypeWithLambdas()
        {
            MyStaticClass.Reset();
            BoundPropertyDescriptor test;

            test = new BoundPropertyDescriptor(typeof(MyStaticClass), () => MyStaticClass.StaticStringProperty, "StaticStringProperty", "", "");
            Assert.IsFalse(test.IsReadOnly);
            Assert.IsTrue(test.GetValue(null).Equals("uninitialized"));
            test.SetValue(null, "xxx");
            Assert.IsTrue(test.GetValue(null).Equals("xxx"));
            Assert.IsTrue(MyStaticClass.StaticStringProperty == "xxx");

            test = new BoundPropertyDescriptor(typeof(MyStaticClass),  () => MyStaticClass.StaticIntProperty, "StaticIntProperty", "", "");
            Assert.IsFalse(test.IsReadOnly);
            Assert.IsTrue(test.GetValue(null).Equals(5));
            test.SetValue(null, 10);
            Assert.IsTrue(test.GetValue(null).Equals(10));
            Assert.IsTrue(MyStaticClass.StaticIntProperty == 10);

            test = new BoundPropertyDescriptor(typeof(MyStaticClass), () => MyStaticClass.StaticStringAsymmetricalAccessProperty, "StaticStringAsymmetricalAccessProperty", "", "");
            Assert.IsTrue(test.IsReadOnly);
            Assert.IsTrue(test.GetValue(null).Equals("uninitialized"));
            test.SetValue(null, "xxx");
            Assert.IsTrue(test.GetValue(null).Equals("xxx"));
            Assert.IsTrue(MyStaticClass.StaticStringAsymmetricalAccessProperty == "xxx");

            test = new BoundPropertyDescriptor(typeof(MyStaticClass), () => MyStaticClass.StaticIntAsymmetricalProperty, "StaticIntAsymmetricalProperty", "", "");
            Assert.IsTrue(test.IsReadOnly);
            Assert.IsTrue(test.GetValue(null).Equals(5));
            test.SetValue(null, 10);
            Assert.IsTrue(test.GetValue(null).Equals(10));
            Assert.IsTrue(MyStaticClass.StaticIntAsymmetricalProperty == 10);
        }