Пример #1
0
        public void Test1()
        {
            Type type = null;

            Type[]     types  = null;
            MethodInfo mInfo  = null;
            MethodInfo mInfo2 = null;

            Object var = null;
            Object obj = null;

            // [A] Vanilla: Class does not extend (other than Object)/implement

            type = Type.GetType("System.Reflection.Tests.Co4611_a3");
            Assert.NotNull(type);
            Assert.Equal("Co4611_a3", type.Name);

            mInfo = type.GetMethod("MethodA", new Type[1] {
                typeof(System.String)
            });
            Assert.NotNull(mInfo);

            obj = new Co4611_a3();
            var = mInfo.Invoke(obj, (Object[])(new string[] { "test string" }));
            Assert.Equal("test string", (string)var);

            mInfo2 = mInfo.GetBaseDefinition();
            Assert.Equal(mInfo, mInfo2);

            Assert.Equal("MethodA", mInfo2.Name);
            Assert.Equal(type, mInfo2.DeclaringType);

            types    = new Type[2];
            types[0] = typeof(System.String);
            types[1] = typeof(System.Int32);
            mInfo    = type.GetMethod("MethodA", types);
            Assert.NotNull(mInfo);

            mInfo2 = mInfo.GetBaseDefinition();
            Assert.Equal(mInfo2, mInfo);
            Assert.Equal("MethodA", mInfo2.Name);
            Assert.Equal(type, mInfo2.DeclaringType);
            // Get method: public void MethodA (Int32 i32)
            types    = new Type[1];
            types[0] = typeof(System.Int32);
            mInfo    = type.GetMethod("MethodA", types);
            Assert.NotNull(mInfo);
            mInfo2 = mInfo.GetBaseDefinition();
            Assert.Equal(mInfo, mInfo2);
            Assert.Equal("MethodA", mInfo2.Name);
            Assert.Equal(type, mInfo2.DeclaringType);
        }
Пример #2
0
        public void Test1()
        {
            Type type = null;
            Type[] types = null;
            MethodInfo mInfo = null;
            MethodInfo mInfo2 = null;

            Object var = null;
            Object obj = null;

            // [A] Vanilla: Class does not extend (other than Object)/implement

            type = Type.GetType("System.Reflection.Tests.Co4611_a3");
            Assert.NotNull(type);
            Assert.Equal("Co4611_a3", type.Name);

            mInfo = type.GetMethod("MethodA", new Type[1] { typeof(System.String) });
            Assert.NotNull(mInfo);

            obj = new Co4611_a3();
            var = mInfo.Invoke(obj, (Object[])(new string[] { "test string" }));
            Assert.Equal("test string", (string)var);

            mInfo2 = mInfo.GetBaseDefinition();
            Assert.Equal(mInfo, mInfo2);

            Assert.Equal("MethodA", mInfo2.Name);
            Assert.Equal(type, mInfo2.DeclaringType);

            types = new Type[2];
            types[0] = typeof(System.String);
            types[1] = typeof(System.Int32);
            mInfo = type.GetMethod("MethodA", types);
            Assert.NotNull(mInfo);

            mInfo2 = mInfo.GetBaseDefinition();
            Assert.Equal(mInfo2, mInfo);
            Assert.Equal("MethodA", mInfo2.Name);
            Assert.Equal(type, mInfo2.DeclaringType);
            // Get method: public void MethodA (Int32 i32)
            types = new Type[1];
            types[0] = typeof(System.Int32);
            mInfo = type.GetMethod("MethodA", types);
            Assert.NotNull(mInfo);
            mInfo2 = mInfo.GetBaseDefinition();
            Assert.Equal(mInfo, mInfo2);
            Assert.Equal("MethodA", mInfo2.Name);
            Assert.Equal(type, mInfo2.DeclaringType);
        }