public MyTestStruct(int val) { _typeName = new MyOtherStruct(val); privateField = val; privateObjectField = val; PrivateProperty = val; PrivateObjectProperty = val; PublicProperty = val; PublicProperty2 = "nice"; }
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); }
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); }