title: Type aliases in C#
body: <p>I'm looking for ways to add syntactic sugar to a project, and am considering adding an <code>Alias</code> class, that is a bit reminiscent of <code>typedef</code> in C++, with significant differences.  The purposes of it are to provide a way to easily create shortened aliases for complex typenames, and to allow more flexibility with method overloading. It would look something like this:</p>
  
  <h2>The Class</h2>
  
  <pre><code>public class Alias&lt;T&gt;
  {
      private T Data { get; set; }
  
      public static implicit operator T(Alias&lt;T&gt; rhs)
      {
          return rhs.Data;
      }
  
      public static implicit operator Alias&lt;T&gt;(T rhs)
      {
          return new Alias&lt;T&gt; { Data = rhs };
      }
  
      // Dereferencing operator
      public static T operator ~(Alias&lt;T&gt; rhs)
      {
          return rhs.Data;
      }
  }
  </code></pre>
  
  <h2>Use Case 1: Shorten complex type names</h2>
  
  <pre><code>// Declare alias somewhere for a cumbersome type, 
  // like a dictionary of dictionaries
  class UserFields : Alias&lt;Dictionary&lt;string, string&gt;&gt; {}
  class UserInfos : Alias&lt;Dictionary&lt;int, UserFields&gt;&gt; {}
  
  // Now use it
  UserFields fields = new UserFields();
  UserInfos infos = new UserInfos();
  (~infos)[0] = fields;
  </code></pre>
  
  <h2>Use Case 2: Method overloading</h2>
  
  <pre><code>// Declare some aliases
  class UserId : Alias&lt;Int64&gt; {}
  class ProductId : Alias&lt;Int64&gt; {}
  
  // Now we can distinguish between them, though they
  // are both Int64's
  public void DoSomething(UserId userId) { ... }
  public void DoSomething(ProductId productId) { ... }
  </code></pre>
  
  <p><hr>
  The examples are contrived, but hopefully illustrate my intentions.  I'm afraid this might end up being hacky, with unexpected consequences. What are some of the pitfalls and problems with using the <code>Alias</code> class as described?</p>