title: How to check assignability of types at runtime in C#?
body: <p>The <code>Type</code> class has a method <code>IsAssignableFrom()</code> that almost works.  Unfortunately it only returns true if the two types are the same or the first is in the hierarchy of the second. It says that <code>decimal</code> is not assignable from <code>int</code>, but I'd like a method that would indicate that <code>decimal</code>s are assignable from <code>int</code>s, but <code>int</code>s are not always assignable from <code>decimal</code>s.  The compiler knows this but I need to figure this out at runtime.  </p>
  
  <p>Here's a test for an extension method.</p>
  
  <pre><code>[Test]
  public void DecimalsShouldReallyBeAssignableFromInts()
  {
      Assert.IsTrue(typeof(decimal).IsReallyAssignableFrom(typeof(int)));
      Assert.IsFalse(typeof(int).IsReallyAssignableFrom(typeof(decimal)));
  }
  </code></pre>
  
  <p>Is there a way to implement <code>IsReallyAssignableFrom()</code> that would work like <code>IsAssignableFrom()</code> but also passes the test case above?</p>
  
  <p>Thanks!</p>
  
  <p>Edit:</p>
  
  <p>This is basically the way it would be used.  This example does not compile for me, so I had to set <code>Number</code> to be <code>0</code> (instead of <code>0.0M</code>).</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]
  public class MyAttribute : Attribute
  {
      public object Default { get; set; }
  }
  
  public class MyClass
  {
      public MyClass([MyAttribute(Default= 0.0M)] decimal number)
      {
          Console.WriteLine(number);
      }
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Error 4 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type </p>
  </blockquote>