title: 'casting' with reflection
body: <p>Consider the following sample code:</p>
  
  <pre><code>class SampleClass
  {
      public long SomeProperty { get; set; }
  }
  
  public void SetValue(SampleClass instance, decimal value)
  {
      // value is of type decimal, but is in reality a natural number =&gt; cast
      instance.SomeProperty = (long)value;
  }
  </code></pre>
  
  <p>Now I need to do something similar through reflection:</p>
  
  <pre><code>void SetValue(PropertyInfo info, object instance, object value)
  {
      // throws System.ArgumentException: Decimal can not be converted to Int64
      info.SetValue(instance, value)  
  }
  </code></pre>
  
  <p>Note that I cannot assume that the PropertyInfo always represents a long, neither that value is always a decimal. However, I know that value can be casted to the correct type for that property.</p>
  
  <p>How can I convert the 'value' parameter to the type represented by PropertyInfo instance through reflection ?</p>