Hey There
I have a custom attribute :
public class MenuItemAttribute : Attribute
{
}
and i have a class with a few methods:
public class HelloWorld
{
[MenuItemAttribute]
public void Shout()
{
}
[MenuItemAttribute]
public void Cry()
{
}
public void RunLikeHell()
{
}
}
Using reflection, how can i get only the methods that are decorated with the custom attribute?
So far i have this:
string assemblyName = fileInfo.FullName;
byte[] assemblyBytes = File.ReadAllBytes(assemblyName);
Assembly assembly = Assembly.Load(assemblyBytes);
foreach (Type type in assembly.GetTypes())
{
System.Attribute[] attributes = System.Attribute.GetCustomAttributes(type);
foreach (Attribute attribute in attributes)
{
if (attribute is MenuItemAttribute)
{
//Get me the method info
//MethodInfo[] methods = attribute.GetType().GetMethods();
}
}
}
What i need now is to get the method name, the return type, as well as the parameters it accepts.