When you find a lack of methods from what you need, you can always write your own extension methods.
public static Type GetEssenceType(this Type node) {
for(Type head=node, next; ; node=next)
if(null==(next=node.GetElementType()))
return node!=head?node:null;
}
It returns the type of the innermost element (which I called the entity type ) if the given type (with a name nodein the code) was a type that has an element type; otherwise null.
Edit:
Type has an internal method that does the same:
internal virtual Type GetRootElementType()
{
Type elementType = this;
while (elementType.HasElementType)
{
elementType = elementType.GetElementType();
}
return elementType;
}
:
var bindingAttr=BindingFlags.Instance|BindingFlags.NonPublic;
var method=typeof(Type).GetMethod("GetRootElementType", bindingAttr);
var rootElementType=(Type)method.Invoke(givenType, null);
, GetRootElementType , .