I'm doing a runtime assembly load, but i don't know the names of any classes or methods. I wan't to list all classes in my assembly with their declared methods, not those inherited from System.Object.
This is the code:
string str = "";
Assembly assembly = Assembly.LoadFile(@"c:\components.dll");
foreach (Type type in assembly.GetTypes())
{
if (type.IsClass == true)
{
str += type.Name + "\n";
MethodInfo[] methodInfo = type.GetMethods(BindingFlags.DeclaredOnly);
foreach (MethodInfo mi in methodInfo)
{
str += "\t" + mi.Name + "\n";
}
}
}
MessageBox.Show(str);
This is the components.dll:
public class component01
{
public string myName = "component01";
public string getMyName()
{
return myName;
}
}
public class component02
{
public string myName = "component02";
public string getMyName()
{
return myName;
}
}
The result:
component01
component02
And if i remove the bindingflag:
component01
getMyName
ToString
Equals
GetHashcode
GetType
component02
getMyName
ToString
Equals
GetHashcode
GetType
I only want the getMyName
method shown.