示例#1
0
        public void TestAccessProperty_InstancePrivate()
        {
            ReflectSampleClass1 o = new ReflectSampleClass1();
            IReflector r = Reflector.Bind(o, ReflectorPolicy.InstanceAllIgnoreCase);
            Type t = r.GetPropertyType("Name");
            Assert.IsTrue(t == typeof(string));

            object val = r.GetPropertyValue("Name");
            Assert.AreEqual("sample1", val);

            Assert.IsTrue(r.ExistProperty("name"));
            Assert.IsTrue(r.ExistProperty("Name"));

            Assert.IsFalse(r.ExistProperty("P"));
        }
示例#2
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"));
        }
示例#3
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);
        }
示例#4
0
        public void TestAccessProperty_InstancePrivate()
        {
            ReflectSampleClass1 o = new ReflectSampleClass1();
            IReflector          r = Reflector.Bind(o, ReflectorPolicy.InstanceAllIgnoreCase);
            Type t = r.GetPropertyType("Name");

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

            object val = r.GetPropertyValue("Name");

            Assert.AreEqual("sample1", val);

            Assert.IsTrue(r.ExistProperty("name"));
            Assert.IsTrue(r.ExistProperty("Name"));

            Assert.IsFalse(r.ExistProperty("P"));
        }
示例#5
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"));
        }
示例#6
0
        public void TestAccessProperty_InstancePublic()
        {
            ReflectSampleClass1 o = new ReflectSampleClass1();
            IReflector          r = Reflector.Bind(o, ReflectorPolicy.InstancePublicIgnoreCase);
            Type t = r.GetPropertyType("count");

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

            object val = r.GetPropertyValue("Count");

            Assert.AreEqual(3, val);

            Assert.IsTrue(r.ExistProperty("count"));
            Assert.IsTrue(r.ExistProperty("Count"));

            r.SetPropertyValue("count", 10);
            Assert.AreEqual(10, o.Count);
        }
示例#7
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);
        }
示例#8
0
        public void TestAccessProperty_InstancePublic()
        {
            ReflectSampleClass1 o = new ReflectSampleClass1();
            IReflector r = Reflector.Bind(o, ReflectorPolicy.InstancePublicIgnoreCase);
            Type t = r.GetPropertyType("count");
            Assert.IsTrue(t == typeof(int));

            object val = r.GetPropertyValue("Count");
            Assert.AreEqual(3, val);

            Assert.IsTrue(r.ExistProperty("count"));
            Assert.IsTrue(r.ExistProperty("Count"));

            r.SetPropertyValue("count", 10);
            Assert.AreEqual(10, o.Count);
        }