I need to fetch a C# type by name, where the interface should be pretty much identical to typeof
except that the string is named at runtime instead of the type being named at compilation time- i.e. typeof(x) == runtime_typeof("x")
for all x
. Fairly critically, I also need to deal with various generic situations like generic definitions and generic types.
I've seen some other solutions in C# for getting type by name but they all seem to involve CLR mangled names rather than C# source names.
Furthermore, I need to retrieve a source name for a given Type
object that should be of the same form.
How can I look up types by C# source name and retrieve a C# source name from a type?
Edit: Assembly qualified names and C# source names are not the same thing. Hence the explicitness in the question.
What I'm really looking for is that the names should be identical to the names you would use to reference them from C# source code- so IEnumerable<T>
or IEnumerable<>
, rather than IEnumerable
[1]` or whatever. Requiring the full namespace is fine for me and I already know what assemblies to look in, so it's mostly an issue of what happens when generics and name mangling are involved.