For example, I want to have a method to get typeof(int)
from "int"
, typeof(List<int>)
from "List<int>"
, typeof(Dictionary<string, int>)
from "Dictionary<string,int>"
, etc.
If the friendly name is an ambiguous one in the calling context, it's ok to throw an exception or simply return a null.
I can use a dictionary to store the map for all built-in friendly types, but it would be too complicated to map every concrete generic type manually. I cannot find a way to build up all the friendly names I may need.
Is there some "eval" method in C# like in some script languages? I.e. so I can simply run typeof
with the friendly name as input and get a Type
object reference as the return value?