title: How to check if an object is nullable?
body: <p>How do I check if a given object is nullable in other words how to implement the following method...</p>
  <pre><code>bool IsNullableValueType(object o)
  {
      ...
  }
  </code></pre>
  <p>I am looking for nullable <em>value types.</em> I didn't have reference types in mind.</p>
  <pre><code>//Note: This is just a sample. The code has been simplified 
  //to fit in a post.
  
  public class BoolContainer
  {
      bool? myBool = true;
  }
  
  var bc = new BoolContainer();
  
  const BindingFlags bindingFlags = BindingFlags.Public
                          | BindingFlags.NonPublic
                          | BindingFlags.Instance
                          ;
  
  
  object obj;
  object o = (object)bc;
  
  foreach (var fieldInfo in o.GetType().GetFields(bindingFlags))
  {
      obj = (object)fieldInfo.GetValue(o);
  }
  </code></pre>
  <p><code>obj</code> now refers to an object of type <code>bool</code> (<code>System.Boolean</code>) with value equal to <code>true</code>. What I really wanted was an object of type <code>Nullable&lt;bool&gt;</code></p>
  <p>So now as a work around I decided to check if o is nullable and create a nullable wrapper around obj.</p>