reflection: getting a field's type

  • Thread starter Thread starter Brad Williams
  • Start date Start date
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
 
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.
 
Back
Top