Choose Method Based on Attribute?

L

localhost

I have a method in a class with [MyAttribute("x")] on it, and the same
method with different overloads and [MyAttribute("y")] on it.

How can my calling class, via Reflection, pick [MyAttribute("y")]
over the first one?

Thanks.
 
J

Jon Skeet [C# MVP]

localhost said:
I have a method in a class with [MyAttribute("x")] on it, and the same
method with different overloads and [MyAttribute("y")] on it.

How can my calling class, via Reflection, pick [MyAttribute("y")]
over the first one?

Use MemberInfo.GetCustomAttributes on each of the candidate methods,
and look at the values returned.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top