Reflection: Get FieldInfo from PropertyInfo

Posted by Ed Woodcock on Stack Overflow See other posts from Stack Overflow or by Ed Woodcock
Published on 2010-04-20T14:35:42Z Indexed on 2010/04/20 15:23 UTC
Read the original article Hit count: 363

Filed under:
|

Hi guys.

I'm doing some dynamic code generation using Reflection, and I've come across a situation where I need to get the backing field of a property (if it has one) in order to use its FieldInfo object.

Now, I know you can use

.IsDefined(typeof(CompilerGeneratedAttribute), false);

on a FieldInfo to discover whether it's autogenerated, so I assume there's a similar thing for Properties which auto-generate fields?

Cheers, Ed

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection