Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }