views:

39

answers:

2

I have something like this:

public class Foo
{
    public Bar[] Bars{get; set;}
}


public class Bar
{
    public string Name{ get; set; }
}

I start reflecting:

PropertyInfo propertyInfo = typeof(Foo).GetProperty("Bars");

so far so good. I want to reflect deeper:

Type type = _propertyInfo .PropertyType; // this gives me that the type is Bar[]

The type is Bar[], but it is not possible to reflect on type to look for property Name. Is there a way to figure out the trype without the array? Or another way to find the single type of Bar?

+2  A: 
type.GetElementType().Name
David Hedlund
+4  A: 
if (type.HasElementType)
    Console.WriteLine(type.GetElementType().Name);

I wrote the HasElementType because I'm guessing you are also going to need to figure out if your element is an array.

Yuriy Faktorovich
accepted this one cause HasElementType is indeed good to know as well
Natrium