title: How to make C# use int method overload for enum types?
body: <p>I got a class in C# that has multiple overloads for different parameter types:</p>
  
  <pre><code>class Writer
  {
    public Writer Write(bool value)
    {
      // Do something with value
      return this;
    }
    public Writer Write(double value)
    {
      // Do something with value
      return this;
    }
    public Writer Write(int value)
    {
      // Do something with value
      return this;
    }
    public Writer Write&lt;T&gt;(T value) where T : class, IInterface, new()
    {
      // Do something with value
      return this;
    }
  }
  
  class Reader
  {
    public Reader Read(out bool value)
    {
      // Retrieve value
      return this;
    }
    public Reader Read(out double value)
    {
      // Retrieve value
      return this;
    }
    public Reader Read(out int value)
    {
      // Retrieve value
      return this;
    }
    public Reader Read&lt;T&gt;(out T value) where T : class, IInterface, new()
    {
      // value = new T() or null
      return this;
    }
  }
  </code></pre>
  
  <p>Now I want to call <code>Write</code> and <code>Read</code> for multiple variables in a row, one of which is of an <code>enum</code> type. However, that enum type causes difficulties in the method resolving. (Btw: I am used to VB.NET, where <code>Enum</code> types are compatible to <code>Integer</code> parameters.)</p>
  
  <pre><code>enum MyEnum : int
  {
    Foo = 0, Bar = 1
  }
  
  class CallingClass
  {
    public void Call()
    {
      bool b;
      double d;
      int i;
      IInterface o;
      MyEnum e = MyEnum.Foo;
  
      var w = new Writer();
  
      // Unintuitive for Write
      w
        .Write(b)
        .Write(d)
        .Write(i)
        .Write(o)
        .Write((int) e);
  
      // w.Write(e); // resolves to Writer.Write&lt;T&gt;(T)
      // =&gt; Compile error: "MyEnum has to be reference type to match T"
  
      // Even worse for Read, you need a temp variable
      // and can't use fluent code anymore:
  
      var r = new Reader();
      r
        .Read(out b)
        .Read(out d)
        .Read(out i)
        .Read(out o);
      int tmp;
      r.Read(out tmp);
      e = (MyEnum) tmp;
    }
  }
  </code></pre>
  
  <p>Is there any way I can modify <code>Write</code>/<code>Read</code>, <code>Writer</code>/<code>Reader</code> or <code>MyEnum</code> so that <code>w.Write(e)</code> will automatically resolve to <code>Writer.Write(int)</code> and more importantly <code>r.Read(out e)</code> to <code>Reader.Read(int)</code>?</p>