jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.77k stars 630 forks source link

Provide virtual `ElementType` property at the `TypeReference` level #841

Open Zastai opened 2 years ago

Zastai commented 2 years ago

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.