示例#1
0
        public void TestAccessField_InstancePrivate()
        {
            ReflectSampleClass1 o = new ReflectSampleClass1();
            IReflector          r = Reflector.Bind(o, ReflectorPolicy.InstanceAll);
            Type t = r.GetFieldType("_name");

            Assert.IsTrue(t == typeof(string));

            object val = r.GetFieldValue("_name");

            Assert.AreEqual("sample1", val);

            Assert.IsTrue(r.ExistField("_name"));
            Assert.IsFalse(r.ExistField("_Name"));

            Assert.IsFalse(r.ExistField("V"));
        }
示例#2
0
        public void TestAccessField_InstancePublic()
        {
            ReflectSampleClass1 o = new ReflectSampleClass1();
            IReflector          r = Reflector.Bind(o, ReflectorPolicy.InstancePublic);
            Type t = r.GetFieldType("X");

            Assert.IsTrue(t == typeof(int));

            object val = r.GetFieldValue("X");

            Assert.AreEqual(5, val);

            Assert.IsTrue(r.ExistField("X"));
            Assert.IsFalse(r.ExistField("x"));

            r.SetFieldValue("X", 10);
            Assert.AreEqual(10, o.X);
        }