I need to be able to read the value of my attribute from within my Method, how can I do that?
[MyAttribute("Hello World")]
public void MyMethod()
{
// Need to read the MyAttribute attribute and get its value
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to call the
GetCustomAttributesfunction on aMethodBaseobject.The simplest way to get the
MethodBaseobject is to callMethodBase.GetCurrentMethod. (Note that you should add[MethodImpl(MethodImplOptions.NoInlining)])For example:
You can also get the
MethodBasemanually, like this: (This will be faster)