/// <summary>
        /// 获得反射的方法
        /// </summary>
        public List <string> GetMethodsReflect()
        {
            List <string> list = new List <string>();
            MemberTypes   Mymembertypes;

            // Get the type of a chosen class.
            Type Mytype = Type.GetType(NamespaceAndClass);

            // Get the MemberInfo array.
            MemberInfo[] Mymembersinfoarray = Mytype.GetMethods();
            // Get and display the name and the MemberType for each member.
            foreach (MemberInfo Mymemberinfo in Mymembersinfoarray)
            {
                Mymembertypes = Mymemberinfo.MemberType;
                if (Mymembertypes.ToString() == "Method")
                {
                    list.Add(Mymemberinfo.Name);
                    if (Mymemberinfo.Name == "SetCarInfoMethod")
                    {
                    }
                }
            }
            return(list);
        }
Example #2
0
    public static int Main(string[] args)
    {
        Console.WriteLine("\nReflection.MemberTypes");
        MemberTypes Mymembertypes;

        // Get the type of a chosen class.
        Type Mytype = Type.GetType
                          ("System.Reflection.ReflectionTypeLoadException");

        // Get the MemberInfo array.
        MemberInfo[] Mymembersinfoarray = Mytype.GetMembers();

        // Get and display the name and the MemberType for each member.
        foreach (MemberInfo Mymemberinfo in Mymembersinfoarray)
        {
            Mymembertypes = Mymemberinfo.MemberType;
            Console.WriteLine("The member {0} of {1} is a {2}.", Mymemberinfo.Name, Mytype, Mymembertypes.ToString());
        }
        return(0);
    }