Beispiel #1
0
        public void TestReflectionSetStructPropertyValueBoxed()
        {
            var myTestStruct = new MyTestStruct();

            myTestStruct.SetStructPropertyValue("PrivateObjectProperty", 123);
            var boxedValue = myTestStruct.GetStructPropertyValue <MyTestStruct, object>("PrivateObjectProperty");

            Assert.Equal(123, boxedValue);
        }
Beispiel #2
0
        public void TestReflectionStructPublicPropertyGetAndSet()
        {
            var i = new MyTestStruct(10);
            var publicProperty1 = i.GetStructPropertyValue <MyTestStruct, int>("PublicProperty");

            Assert.Equal(10, publicProperty1);

            i.SetStructPropertyValue("PublicProperty", 15);
            var publicProperty2 = i.GetStructPropertyValue <MyTestStruct, int>("PublicProperty");

            Assert.Equal(15, publicProperty2);
        }
Beispiel #3
0
        public void TestReflectionSetFieldValueBoxed()
        {
            var testObject = new ReflectionTestObject();

            testObject.SetFieldValue("PrivateValue2", 123);
            Assert.Equal(123, testObject.GetFieldValue <object>("PrivateValue2"));

            var testStruct = new MyTestStruct(123);

            testStruct.SetStructFieldValue("privateObjectField", 456);
            Assert.Equal(456, testStruct.GetFieldValue <object>("privateObjectField"));
        }
Beispiel #4
0
        public void TestReflectionStructPrivatePropertyGetAndSet2()
        {
            var          i                = new MyTestStruct(10);
            const string propertyName     = "PrivateProperty";
            var          privateProperty1 = i.GetStructPropertyValue <MyTestStruct, int>(propertyName);

            Assert.Equal(10, privateProperty1);

            i.SetStructPropertyValue(propertyName, 5);
            var privateProperty2 = i.GetStructPropertyValue <MyTestStruct, int>(propertyName);

            Assert.Equal(5, privateProperty2);
        }
Beispiel #5
0
        public void TestReflectionStructPrivatePropertyGetAndSet()
        {
            var          i                = new MyTestStruct(10);
            const string propertyName     = "PublicProperty2";
            var          privateProperty1 = i.GetStructPropertyValue <MyTestStruct, string>(propertyName);

            Assert.Equal("nice", privateProperty1);

            i.SetStructPropertyValue(propertyName, "test2");
            var privateProperty2 = i.GetStructPropertyValue <MyTestStruct, string>(propertyName);

            Assert.Equal("test2", privateProperty2);
        }
Beispiel #6
0
        public void TestReflectionStructFieldGetAndSet()
        {
            var i      = new MyTestStruct(5);
            var newVal = new MyOtherStruct(3);

            i.SetStructFieldValue("_typeName", newVal);
            i.SetStructFieldValue("privateField", 45);

            var typeNameField  = typeof(MyTestStruct).GetFieldCached("_typeName");
            var typeNameActual = (MyOtherStruct)typeNameField.GetValue(i);
            var privateField   = i.GetFieldValue <int>("privateField");

            Assert.Equal(45, privateField);

            var typeName = i.GetFieldValue <MyOtherStruct>("_typeName");

            Assert.Equal(typeNameActual.Val, typeName.Val);
            Assert.Equal(3, typeName.Val);
        }