Esempio n. 1
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);
        }
Esempio n. 2
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"));
        }