I have being using reflection to create a list of methods that the user would use in a dynamic generated menu (I'am in unity). I'am using:
MethodInfo[] methodInfos = myObject.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
But not all public methods of the class should appear in this menu, so I was wondering, is there some flag which I could use to mark only the methods that I need?
And then use this "custom flag" to get those methods through reflection. Thanks :).
Use custom attribute:
and allow user to mark methods:
Then, on methods lookup, inspect metadata for this attribute:
If you need to provide an ability for user to define menu path, then extend your attribute with custom parameter, something like this:
Another option is to throw away custom way to make plugins, and use something out of the box, e.g., MEF.