예제 #1
0
 public MyTestStruct(int val)
 {
     _typeName             = new MyOtherStruct(val);
     privateField          = val;
     privateObjectField    = val;
     PrivateProperty       = val;
     PrivateObjectProperty = val;
     PublicProperty        = val;
     PublicProperty2       = "nice";
 }
예제 #2
0
        public void TestReflectionStructStaticGetAndSet()
        {
            var i = new MyOtherStruct(5);

            i.SetStructFieldValue("PrivateVal", 3);

            var typeNameField    = typeof(MyOtherStruct).GetFieldCached("PrivateVal");
            var privateValActual = (int)typeNameField.GetValue(i);

            var privateVal = i.GetFieldValue <int>("PrivateVal");

            Assert.Equal(privateValActual, privateVal);
            Assert.Equal(3, privateVal);
        }
예제 #3
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);
        }