title: Is there a way to write an Extension Method that applies to multiple types?
body: <p>I'm trying to write an extension method that will add the function <code>HasFactor</code> to the class <code>int</code> in C#.  This works wonderfully, like so:</p>
  
  <pre><code>static class ExtendInt
  {
      public static bool HasFactor(this int source, int factor)
      {
          return (source % factor == 0);
      }
  }
  
  class Program
  {
      static void Main()
      {
          int i = 50;
          int f = 2;
          bool b = i.HasFactor(f);
          Console.WriteLine("Is {0} a factor of {1}? {2}",f,i,b);
          Console.ReadLine();
       }
  }
  </code></pre>
  
  <p>This works great because variable <code>i</code> in the <code>Main()</code> method above is declared as an <code>int</code>.  However, if <code>i</code> is declared as an <code>Int16</code> or an <code>Int64</code>, the extension method does not show up unless it is explicitly cast as an <code>int</code> or <code>Int32</code>.</p>
  
  <p>I now would like to apply the same <code>HasFactor</code> method to <code>Int16</code> and <code>Int64</code>.  However, I'd rather not write separate extension methods for each type of <code>int</code>.  I <em>could</em> write a single method for <code>Int64</code> and then explicitly cast everything as an <code>Int64</code> or <code>long</code> in order for the extension method to appear.  </p>
  
  <p>Ideally, I'd prefer to have the same extension method apply to all three types without having to copy and paste a lot of code.</p>
  
  <p><strong>Is this even possible in C#?</strong>  If not, is there a recommended best-practice for this type of situation?</p>