title: How to explicity cast a type to Interface at runtime
body: <p>Using reflection, I have got all the types in the assembly. How can I cast the Type t to an ICommand if i know that it implements Interface "ICommand"</p>
  
  <pre><code>ICommand C;
  foreach(Type t in asm.GetTypes())
  {
  
      if (t.GetInterfaces()[0].Name is "ICommand")
      {
          C = (ICommand)t; //throws Exception here - Unable
                           //to cast to ICommand
         RootDir.AddCommand(C, t.Namespace.Split('.'));
      }
   }
  </code></pre>
  
  <p>An example of the Type I am trying to cast</p>
  
  <pre><code>public interface ICommand
  {
      string HelpDescription { get; }
      void Execute(CommandClass CC);
  }
  
  
  class CurrentDir : ICommand
  {
      public string HelpDescription =&gt; "Current Directory - Change current directory";
  
      public static explicit operator CurrentDir (Type T)
      {
          return new CurrentDir();
      }
  
      void ICommand.Execute(CommandClass CC)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>How should I implement this such that It can cast from System.Type to ICommand?</p>