It is never possible to mention an anonymous type directly, but you should not need to. Generic type inference means that you don't need to specify the <T>
in .ToList<T>()
- the compiler will automatically inject the invented type.
There are only a few ways to refer to an anonymous type:
- via
someObj.GetType()
, wheresomeObj
is an instance of an anonymous type - via generics, as a
T
, by calling a generic method via generic type inference (as inToList()
) - various other usages of reflection, pulling in the
T
viaGetGenericTypeParameters()