title: How to test whether a value is boxed in C# / .NET?
body: <p>I'm looking for a way to write code that tests whether a value is boxed. </p>
  
  <p>My preliminary investigations indicate that .NET goes out of its way to conceal the fact, meaning that <code>GetType()</code> and <code>IsValueType</code> don't reveal the difference between a boxed value and an unboxed value. For example, in the following LinqPad C# expressions, I have faith that <code>o1</code> is boxed and <code>i1</code> is not boxed, but I would like a way to test it in code, or, second best, a way to know <em>FOR SURE</em> when looking at any variable or value, even if its type is "dynamic" or "object," whether it's boxed or not boxed. </p>
  
  <p>Any advice?</p>
  
  <pre><code>// boxed? -- no way to tell from these answers!
  object o1 = 123;
  o1.GetType().Dump("o1.GetType()");
  o1.GetType().IsValueType.Dump("o1.GetType().IsValueType");
  
  // not boxed? -- no way to tell from these answers!
  int i1 = 123;
  i1.GetType().Dump("i1.GetType()");
  i1.GetType().IsValueType.Dump("i1.GetType().IsValueType");
  </code></pre>