reflection: getting a field's type

B

Brad Williams

I'm needing to reflect on classes to find any fields they may declare of a
certain type. However, the MemberInfo objects returned by Type.FindMembers
do not expose the field's type, to my amazement.

Now the MemberInfo object returned in this case is actually of the more
derived class RuntimeFieldInfo, which *does* have a FieldType property which
is exactly what I want (I see it in the debugger). But RuntimeFieldInfo is
"internal" so I can't use it in my code!

Is there a way to get the type of a field of a class through reflection? I
could (ahem) parse MemberInfo.ToString(), but ...

Thanks,
Brad Williams
 
B

Brad Williams

Is there a way to get the type of a field of a class through reflection?

I figured it out 2 minutes after posting the question: use Type.GetFields()
instead of Type.FindMembers(), because FieldInfo exposes the field's type.
 

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