Hi Bill,
Think of it like this: If you knew that a MemberInfo instance was a property,
you would cast it to PropertyInfo. And if a MemberInfo was a field, then you
could cast it to FieldInfo. So what do you cast a MemberInfo to that is a
nested Type? Type. (TypeInfo would be semantically equivalent to Type, so
there is no need for a TypeInfo class :)
class Outer
{
public class Inner
{
public int AField;
}
}
class Program
{
static void Main()
{
foreach (MemberInfo member in typeof(Outer).G etMembers())
{
if (member.MemberT ype == MemberTypes.Nes tedType)
{
// MemberInfo that is a NestedType is just a Type itself
Type nestedType = (Type) member;
Console.WriteLi ne("Members of {0}: ", nestedType);
Console.WriteLi ne();
foreach (MemberInfo nestedMember in nestedType.GetM embers())
{
Console.WriteLi ne("Nested Member: " + nestedMember.Na me);
}
}
}
}
--
Dave Sexton
"bill" <wg****@draper. comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
All,
Can anyone supply an example or reference to an example of using
reflection to determine the data types contained in a nested stucture
in C#? Once I get the list of MemberInfo[] and determine that
MemberInfo[i].MemberType.ToS tring().Equals( "NestedType "), I cannot
figure out how to drill down from that point.
TIA,
Bill