title: Creating an object from unknown type
body: <p>I have three classes. A B and C. A and B both derived from C (C has OAuth properties), and A and B both have different properties other than C properties</p>
  
  <p>I have a function that sets the OAuth properties of both A and B, but because they are different types I pass in an object through the method. I then check to see if A is A and B is B, but I don't know where to set the OAuth properties (i don't want to duplicate my code)</p>
  
  <pre><code>public string SerializeForAPI(object myObject)
  {
      JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
  
      if (myObject is A)
      {
          A data = (A)myObject; 
      }
      else if (myObject is B) 
      {
          B data = (B)myObject;
      }
      // these are obviously not set because the object is within the if statement
      data.oauth_consumer_key = this.ConsumerKey;
      data.oauth_token = this.Token;
  
      string serialized = jsonSerializer.Serialize(data);
      ...
  }
  </code></pre>