public void TestMethodOf()
        {
            var obj = new DummyType();

            var actualMethod1 = typeof(DummyType).GetMethod("DoWork", Type.EmptyTypes);
            var actualMethod2 = typeof(DummyType).GetMethod("DoWork", new[] { typeof(string) });
            var actualMethod3 = typeof(DummyType).GetMethod("GetValue", new[] { typeof(string), typeof(int) });
            var method1 = ReflectionUtility.MethodOf(() => obj.DoWork());
            var method2 = ReflectionUtility.MethodOf(() => obj.DoWork(string.Empty));
            var method3 = ReflectionUtility.MethodOf(() => obj.GetValue(string.Empty, 0));

            Assert.IsNotNull(method1);
            Assert.IsNotNull(method2);
            Assert.IsNotNull(method3);
            Assert.AreEqual(actualMethod1, method1);
            Assert.AreEqual(actualMethod2, method2);
            Assert.AreEqual(actualMethod3, method3);
        }
示例#2
0
        public void TestMethodOf()
        {
            var obj = new DummyType();

            var actualMethod1 = typeof(DummyType).GetMethod("DoWork", Type.EmptyTypes);
            var actualMethod2 = typeof(DummyType).GetMethod("DoWork", new[] { typeof(string) });
            var actualMethod3 = typeof(DummyType).GetMethod("GetValue", new[] { typeof(string), typeof(int) });
            var method1       = ReflectionUtility.MethodOf(() => obj.DoWork());
            var method2       = ReflectionUtility.MethodOf(() => obj.DoWork(string.Empty));
            var method3       = ReflectionUtility.MethodOf(() => obj.GetValue(string.Empty, 0));

            Assert.IsNotNull(method1);
            Assert.IsNotNull(method2);
            Assert.IsNotNull(method3);
            Assert.AreEqual(actualMethod1, method1);
            Assert.AreEqual(actualMethod2, method2);
            Assert.AreEqual(actualMethod3, method3);
        }