I want to write a method that will analyze the user attributes of any method (with any number of arguments and any return type), knowing only the information about the method. This function checks if a method has a specific attribute. for example: var tmp = methodInfo.GetCustomAttributes(typeof(LineItemAttribute),false); , and if he has such an attribute, he will execute it. And I want the call to this function to be very easy to use. So, in the example there are three methods and the GetMethodAttributes method that I want to call.
class Test { public static void Main() { } public void Test1(){} public void Test2(int a){} public void Test3(object a, string c, Boolean d); public void GetMethodAttributes(MethodInfo mi) {} }
Ideally, I want to write something like this
public static void Main() { var t = new Test(); GetMethodAttributes(t.Test1); GetMethodAttributes(t.Test2); GetMethodAttributes(t.Test3); }
I do not want to use a string representation of method names, since method names can change, for example:
MethodInfo info = type.GetMethod(name);
Do I have any options? Basically I need a way to use delegates for functions with different sines
reflection c # delegates
vmg Jan 15 '13 at 0:48 2013-01-15 00:48
source share