Get all Methods from a class and all Classes of Assembly

 

using System;

using System.IO;

using System.Reflection;

 

public class Class1

{

    public void GetAllMethodsOfClass()

    {

        DataAccessLogic dal = new DataAccessLogic();

        Type t = dal.GetType();

        MethodInfo[] mi = t.GetMethods();

        foreach (MethodInfo m in mi)

        {

            Label1.Text += m.Name + "()<br/>";

        }

    }

}

 

Get all Classes & Class Methods from an Assembly

 

using System;

using System.IO;

using System.Reflection;

 

public class Class1

{

    public void GetAllClassesAndMethodsOfAssembly()

    {

 

        //Code to load Assembly

        Assembly assem1 = Assembly.Load(AssemblyName.GetAssemblyName("MyAssembly"));

 

        //Another Way

        Assembly assem2 = Assembly.Load("MyAssembly");

 

        //Get List of Class Name

        Type[] types = assem1.GetTypes();

 

        foreach(Type tc in types)

        {

            if (tc.IsAbstract)

            {

                Response.Write("Abstract Class : " + tc.Name);

            }

            else if (tc.IsPublic)

            {

                Response.Write("Public Class : " + tc.Name);

            }

            else if (tc.IsSealed)

            {

                Response.Write("Sealed Class : " + tc.Name);

            }  

 

            //Get List of Method Names of Class

            MemberInfo[] methodName = tc.GetMethods();

 

            foreach (MemberInfo method in methodName)

            {

                if (method.ReflectedType.IsPublic)

                {

                    Response.Write("Public Method : " + method.Name.ToString());

                }

                else

                {

                    Response.Write("Non-Public Method : " + method.Name.ToString());

                }

            }

        }

    }

}