title: Convert "C# friendly type" name to actual type: "int" => typeof(int)
body: <p>I want to get a <code>System.Type</code> given a <em><code>string</code></em> that specifies a (primitive) type's <em>C# friendly name</em>, basically the way the C# compiler does when reading C# source code.</p>
  
  <p>I feel the best way to describe what I'm after is in the form of an unit-test.</p>
  
  <p>My hope is that a general technique exists that can make all the below assertions pass, rather than try to hard-code special cases for special C# names.</p>
  
  <pre><code>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[,][,][][,][][]) ); 
  }
  </code></pre>
  
  <p>What I tried so far:</p>
  
  <p>This question is the complement of <a href="https://stackoverflow.com/q/4615553/11545">an older question of mine</a> asking how to get the "friendly name" from a type. </p>
  
  <p>The answer to that question is: use <code>CSharpCodeProvider</code></p>
  
  <pre><code>using (var provider = new CSharpCodeProvider())
  {
      var typeRef = new CodeTypeReference(typeof(int));
      string friendlyName = provider.GetTypeOutput(typeRef);
  }
  </code></pre>
  
  <p>I can't figure out how (or if possible) to do it the other way around and get the actual C# type from the <code>CodeTypeReference</code> (it also has a ctor that takes a <code>string</code>)</p>
  
  <pre><code>var typeRef = new CodeTypeReference(typeof(int));
  </code></pre>