Get all Methods from a class and all Classes of Assembly
Wed Jan 25 2023 13:58:26 GMT+0000 (Coordinated Universal Time)
Saved by
@javicinhio
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/>";
}
}
}
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());
}
}
}
}
}
content_copyCOPY
http://venkateswarlu.net/dotnet/Get_all_methods_from_a_class.aspx
Comments