TypeReference has properties like IsArray to be able to know what specific type it is without needing a cast.
It also has a GetElementType() method. However, somewhat counter-intuitively, that returns the innermost element type, so for ref decimal[] it returns System.Decimal, and for Func<int, bool>[] it returns System.Func`2 (not a generic instance, losing the int and bool entirely).
So in order not to break the API, could a virtual ElementType property be added at the TypeReference level (with the one on TypeSpecification becoming an override)? That would avoid having to use casts all over the place.
Alternatively, maybe add an overload of GetElementType() taking a boolean "innermost" flag, with the existing no-argument version calling through to that, passing true.
TypeReference
has properties likeIsArray
to be able to know what specific type it is without needing a cast.It also has a
GetElementType()
method. However, somewhat counter-intuitively, that returns the innermost element type, so forref decimal[]
it returnsSystem.Decimal
, and forFunc<int, bool>[]
it returnsSystem.Func`2
(not a generic instance, losing theint
andbool
entirely).So in order not to break the API, could a virtual
ElementType
property be added at the TypeReference level (with the one onTypeSpecification
becoming an override)? That would avoid having to use casts all over the place.Alternatively, maybe add an overload of
GetElementType()
taking a boolean "innermost" flag, with the existing no-argument version calling through to that, passingtrue
.