示例#1
0
        public void GetPropertyValue()
        {
            var test = new TestRelfectionClass {
                Prop1 = null, Prop2 = "asdsada"
            };

            Assert.Equal(test.Prop1, ReflectionHelper.GetPropertyValue(test, nameof(test.Prop1)));
            Assert.Equal(test.Prop2, ReflectionHelper.GetPropertyValue(test, nameof(test.Prop2)));
        }
示例#2
0
        public void SetProtectedFieldValue()
        {
            string newValue = "new value 1";

            var test = new TestRelfectionClass {
            };

            ReflectionHelper.SetNonPublicField(test, "field2", newValue);
            Assert.Equal(newValue, ReflectionHelper.GetNonPublicField(test, "field2"));

            ReflectionHelper.SetNonPublicField(test, "field2", null);
            Assert.Null(ReflectionHelper.GetNonPublicField(test, "field2"));
        }
示例#3
0
        public void SetPropertyValue()
        {
            string newProp1 = "new value 1";

            var test = new TestRelfectionClass {
                Prop1 = null, Prop2 = "asdsada"
            };

            ReflectionHelper.SetPropertyValue(test, nameof(test.Prop1), newProp1);
            ReflectionHelper.SetPropertyValue(test, nameof(test.Prop2), null);

            Assert.Equal(newProp1, test.Prop1);
            Assert.Null(test.Prop2);
        }