In C#, is there a way to get the T from IEnumerable at runtime and use it as a Type?

Viewed 51

Is there a way to get the type T from IEnumerable< T > at runtime and use it as a Type?

Example: I'm iterating through the attributes of an object and I need to check if they're equal, however, I can't use .Equal() with IEnumerable because it doesn't check if what's inside is equal, so I need to use the builtin method .SequenceEqual(), but it doesn't work because it gets the type at runtime, thus it doesn't compile because the generic type has no .SequenceEqual().

The way I've been doing is:

var RuntimeField = ReflectedValue as IEnumerable< T >

Then RuntimeField gets casted to the type and I can use its method, and it works, but I'd need to do that for each T in the application since I can't find a way to get the T value and use it as a Type.

0 Answers
Related