Get property name from class

Posted by Polaris on Stack Overflow See other posts from Stack Overflow or by Polaris
Published on 2010-05-04T10:02:01Z Indexed on 2010/05/04 10:08 UTC
Read the original article Hit count: 209

Filed under:
|

I need property name in my app and I use next code to get it

string PropertyName =SomeClass.GetType().GetProperty("Category").Name;

But I think that is bad idea. Because I use web service classes and I dont know when property names can be changed. This code give me exception only in runtime. But if I write something like this SomeClassInstance.Property.GetProperyName i get exception in moment of compilation and repair this problem. Is it possible to get property name dynamically?

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection