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).GetMembers())
{
if (member.MemberType == MemberTypes.NestedType)
{
// MemberInfo that is a NestedType is just a Type itself
Type nestedType = (Type) member;
Console.WriteLine("Members of {0}: ", nestedType);
Console.WriteLine();
foreach (MemberInfo nestedMember in nestedType.GetMembers())
{
Console.WriteLine("Nested Member: " + nestedMember.Name);
}
}
}
}
--
Dave Sexton
"bill" <wg****@draper.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.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.ToString().Equals("NestedType"), I cannot
figure out how to drill down from that point.
TIA,
Bill