title: Call Method based on Type of Parameter
body: <p>I have an object that can be of type <code>AudioRequest</code> or <code>VideoRequest</code>. Both classes inherit from <code>Request</code>. I have this class:</p>
  
  <pre><code>public static DoThings
  {
      public static void HandleRequest(AudioRequest r)
      {
          // Do things.
      }
  
      public static void HandleRequest(VideoRequest r)
      {
          // Do things.
      }
  }
  </code></pre>
  
  <p>I want to be able to call <code>DoThings.HandleRequest(r)</code> where <code>r</code> can be either a <code>VideoRequest</code> or <code>AudioRequest</code> and have it call the correct one. Is that possible? I have no control over the <code>*Request</code> classes, so I can't do anything to them. I do have control of the <code>DoThings</code> class and the code that calls <code>HandleRequest</code>. This is the code that calls it, it is WebAPI:</p>
  
  <pre><code>public Response Post(Request input)
  {
      return DoThings.HandleRequest(input);
  }
  </code></pre>
  
  <p>The code above gives the error <code>Argument 1: cannot convert from 'Request' to 'AudioRequest'</code>.</p>
  
  <p>The original code that I was cleaning up had this:</p>
  
  <pre><code>if (input.GetType() == typeof(AudioRequest))
  {
      var audioRequest = (AudioRequest)input;
      DoThings.HandleRequest(audioRequest);
  }
  else if (input.GetType() == typeof(VideoRequest))
  {
      var videoRequest = (VideoRequest)input;
      DoThings.HandleRequest(videoRequest);
  }
  </code></pre>
  
  <p>But I figured there was a cleaner way to do this.</p>