title: Looking for a .NET ObjectReflector that will help me simplify reflecting an object
body: <p>I've got a class that receives an object from other unknown modules and so I have to do reflection on the object to get its data, call its methods, etc.</p>
  
  <p>To simplify the code to reflect on the object, I'm building this class:</p>
  
  <pre><code>using System;
  
  namespace ApplicationCore.Helpers
  {
      class ObjectReflector
      {
          public object TheObject { get; set; }
          public Type TheType { get; set; }
  
          public ObjectReflector(object theObject)
          {
              TheObject = theObject;
              TheType = theObject.GetType();
          }
  
          public string GetObjectShortName()
          {
              return TheObject.GetType().Name;
          }
  
          public string GetObjectLongName()
          {
              return TheObject.GetType().ToString();
          }
  
          public T GetPropertyValue&lt;T&gt;(string propertyName)
          {
              return (T)TheType.GetProperty(propertyName).GetValue(TheObject, null);
          }
  
          public T GetMethodValue&lt;T&gt;(string methodName, object[] parameters)
          {
              return (T)TheType.GetMethod(methodName).Invoke(TheObject, parameters);
          }
  
      }
  }
  </code></pre>
  
  <p>So that I have nice, clean code that looks like this:</p>
  
  <pre><code>namespace ApplicationCore.Presenters
  {
      public class SmartFormPresenter
      {
          public UserControl View { get; set; }
  
          public string ShortName { get; set; }
          public string LongName { get; set; }
          public string FirstName { get; set; }
          public int Age { get; set; }
          public int AgePlusTwo { get; set; }
  
          public SmartFormPresenter(object o)
          {
              SmartFormView smartFormView = new SmartFormView();
              View = smartFormView;
              smartFormView.DataContext = this;
  
              ObjectReflector or = new ObjectReflector(o);
              ShortName = or.GetObjectShortName();
              LongName = or.GetObjectLongName();
              FirstName = or.GetPropertyValue&lt;string&gt;("FirstName");
              Age = or.GetPropertyValue&lt;int&gt;("Age");
              AgePlusTwo = or.GetMethodValue&lt;int&gt;("GetAgeInTwoYears", null);
          }
      }
  }
  </code></pre>
  
  <p>But now I need to make methods e.g. to read out not an <strong>int</strong> but a <strong><code>List&lt;Contract&gt;</code></strong> so that I'm going to have to get a <code>List&lt;object&gt;</code> and then reflect on the "object" etc.</p>
  
  <p>So I'm thinking that this has been done before. <strong>Is there any kind of tool or class in .NET called ObjectReflector that will help me simplify the reflection of an object as I'm doing above?</strong></p>