I have a dll which has some classes, these classes have some methods. And some of those methods has another method call inside it.
How can I check whether a method inside a class has a specific method or not. I have done some googling on this and I was able to find the classes inside the dll as follows:
public List < string > GetClassFromDlLstring(string dllName)
{
Assembly assemblies = null;
try
{
assemblies = Assembly.LoadFrom(dllName);
}
catch (Exception ex)
{
}
var allTypes = assemblies.GetTypes();
return (from allType in allTypes where allType.IsClass select allType.ToString()).ToList();
}
And similarly a method to find all the methods inside a class as follows:
public List <string> GetAllTMethodClass(string dllName, string className)
{
var assemblies = Assembly.LoadFrom(dllName);
Type type = assemblies.GetType(className);
var temp = new List <string> ();
try
{
MethodInfo[] methods = type.GetMethods();
//MethodInfo[] methods = type.GetMethods(BindingFlags.Instance);
foreach(MethodInfo meth in methods)
{
if (meth.MemberType == MemberTypes.Method && meth.MemberType != MemberTypes.Property)
temp.Add(meth.Name);
}
}
catch (Exception ex)
{
}
return temp;
}
I have a problem now the function above return property name also.
Further I want to go through the function list and check weather the function contain a particular function or not. How can I achieve this?
Edit 1:
I found the similar post whose link is below
- Look if a method is called inside a method using reflection
- Get types used inside a C# method body