title: Passing an object and its type to a method
body: <p>I have three classes: SomeThing, SomeOtherThing, and YetAntherThing. All three have an identical member called Properties. In each class, it is a key/value pair such that I can reference obj1.Name, obj1.Value, obj2.Name, obj2.Value, obj3.Name, and obj3.Value. I'd like to pass these three objects into a single method that could iterate through their respective "Properties" collections without having to know at compile time which it was operating on. I envision something like:</p>
  
  <pre><code>SomeThing obj1;
  SomeOtherThing obj2;
  YetAntherThing obj3;
  
  DoProperties( obj1, obj1.GetType() );
  DoProperties( obj2, obj2.GetType() );
  DoProperties( obj3, obj3.GetType() );
  
  ...
  
  private void DoProperties( object obj, Type objectType )
  {
      // this is where I get lost. I want to "cast" 'obj' to the type
      // held in 'objectType' so that I can do something like:
      //
      // foreach ( var prop in obj.Properties )
      // {
      //    string name = prop.Name;
      //    string value = prop.Value;
      // }
  }
  </code></pre>
  
  <p>Note: The classes SomeThing, SomeOtherThing, and YetAntherThing are defined externally, I have no control over them or access to their source code, and they are all sealed.</p>