예제 #1
0
        public void TestGetterSetter()
        {
            Simple s = new Simple();

            ReflectionUtil.Set(s, "_a", 44);
            Assert.AreEqual(44, ReflectionUtil.Get(s, "_a"));

            ReflectionUtil.Set(typeof(Simple), "HELLO", "HELLO WORLD");
            Assert.AreEqual("HELLO WORLD", ReflectionUtil.Get(typeof(Simple), "HELLO"));

            ReflectionUtil.Set(s, "IntProperty", 44);
            Assert.AreEqual(44, ReflectionUtil.Get(s, "IntProperty"));

            ReflectionUtil.Set(s, "IntProperty", 1.1);
            Assert.AreEqual(1, ReflectionUtil.Get(s, "IntProperty"));

            Assert.Throws <System.InvalidCastException> (
                () => {
                ReflectionUtil.Set(s, "IntProperty", "1");
            }
                );
        }
예제 #2
0
        public void TestMethodSimpleImplicitCast2()
        {
            Simple s  = new Simple();
            Simple s2 = new Simple();

            ReflectionUtil.CallMethod(s, "SetString", "hoge");
            Assert.AreEqual("hoge", s._s);

            ReflectionUtil.CallMethod(s, "SetString", s2);
            Assert.AreEqual(s2, s._i);

            Assert.Throws <System.Reflection.AmbiguousMatchException> (
                () => {
                ReflectionUtil.CallMethod(s, "SetString", new object[] { null });
            }
                );

            ReflectionUtil.CallMethod(s, "SetString", new NullWithType(typeof(string)));
            Assert.AreEqual(null, s._s);

            ReflectionUtil.CallMethod(s, "SetString", new NullWithType(typeof(Simple)));
            Assert.AreEqual(null, s._s);
        }
예제 #3
0
 public void SetString(Simple s)
 {
     _i = s;
 }
예제 #4
0
 public Simple(Simple i)
 {
     //CSLog.D ("instance one");
     _i = i;
 }