Convierta el nombre del "tipo compatible con C #" al tipo real: "int" => typeof (int)

Quiero conseguir unSystem.Type dado unstring que especifica un tipo (primitivo)C # nombre amistosoBásicamente, la forma en que lo hace el compilador de C # al leer el código fuente de C #.

Siento que la mejor manera de describir lo que busco es en forma de prueba de unidad.

Mi esperanza es que exista una técnica general que pueda hacer pasar todas las aseveraciones a continuación, en lugar de tratar de codificar casos especiales para nombres especiales de C #.

Type GetFriendlyType(string typeName){ ...??... }

void Test(){
    // using fluent assertions

    GetFriendlyType( "bool" ).Should().Be( typeof(bool) );
    GetFriendlyType( "int" ).Should().Be( typeof(int) );

    // ok, technically not a primitive type... (rolls eyes)
    GetFriendlyType( "string" ).Should().Be( typeof(string) ); 

    // fine, I give up!
    // I want all C# type-aliases to work, not just for primitives
    GetFriendlyType( "void" ).Should().Be( typeof(void) );
    GetFriendlyType( "decimal" ).Should().Be( typeof(decimal) ); 

    //Bonus points: get type of fully-specified CLR types
    GetFriendlyName( "System.Activator" ).Should().Be(typeof(System.Activator));

    //Hi, Eric Lippert! 
    // Not Eric? https://stackoverflow.com/a/4369889/11545
    GetFriendlyName( "int[]" ).Should().Be( typeof(int[]) ); 
    GetFriendlyName( "int[,]" ).Should().Be( typeof(int[,]) ); 
    //beating a dead horse
    GetFriendlyName( "int[,][,][][,][][]" ).Should().Be( typeof(int[,][,][][,][][]) ); 
}

Lo que intenté hasta ahora:

Esta pregunta es el complemento deuna vieja pregunta mia preguntando cómo obtener el "nombre descriptivo" de un tipo.

La respuesta a esa pregunta es: usarCSharpCodeProvider

using (var provider = new CSharpCodeProvider())
{
    var typeRef = new CodeTypeReference(typeof(int));
    string friendlyName = provider.GetTypeOutput(typeRef);
}

No puedo averiguar cómo (o si es posible) hacerlo al revés y obtener el tipo de C # real de laCodeTypeReference (También tiene un ctor que lleva unstring)

var typeRef = new CodeTypeReference(typeof(int));

Respuestas a la pregunta(5)

Su respuesta a la pregunta