How do I read an attribute on a class at runtime?

Posted by Zaff on Stack Overflow See other posts from Stack Overflow or by Zaff
Published on 2010-04-16T21:25:31Z Indexed on 2010/04/16 21:33 UTC
Read the original article Hit count: 237

Filed under:
|
|

I am trying to create a generic method that will read an attribute on a class and return that value at runtime. How do would I do this?

Note: DomainName attribute is of class DomainNameAttribute.

[DomainName(“MyTable”)]
Public class MyClass : DomianBase
{}

What I am trying to generate:

//This should return “MyTable”
String DomainNameValue = GetDomainName<MyClass>();

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics