title: How to override NET type converters?
body: <p>I'm working on an ETL-type application which creates entities from csv data files. One field in particular - a boolean field - is proving difficult to work with because systems provide their own interpretation of a bool such as true, false, yes, no, 1, 0 or even -1 etc.</p>
  
  <p>Using the default type converters most of the tests fail:</p>
  
  <pre><code>var b1 = Convert.ChangeType("true", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b2 = Convert.ChangeType("false", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b3 = Convert.ChangeType("True", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b4 = Convert.ChangeType("False", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b5 = Convert.ChangeType("TRUE", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b6 = Convert.ChangeType("FALSE", TypeCode.Boolean, CultureInfo.InvariantCulture);
  
  // All below fail
  var b7 = Convert.ChangeType("yes", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b8 = Convert.ChangeType("no", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b9 = Convert.ChangeType("Yes", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b10 = Convert.ChangeType("No", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b11 = Convert.ChangeType("YES", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b12 = Convert.ChangeType("NO", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b13 = Convert.ChangeType("1", TypeCode.Boolean, CultureInfo.InvariantCulture);
  var b14 = Convert.ChangeType("0", TypeCode.Boolean, CultureInfo.InvariantCulture);
  </code></pre>
  
  <p>What I would like to do is override the default System.ComponentModel.BooleanConverter so that I can provide my own parser to correctly handle above. Any idea how to do this?</p>
  
  <p>This <a href="http://www.hanselman.com/blog/TypeConvertersTheresNotEnoughTypeDescripterGetConverterInTheWorld.aspx">post</a> by Scott Hanselman touches on creating type converters but I wish to override the default one.</p>
  
  <p>For reference here's my entity extractor implementation.</p>
  
  <pre><code>public static TEntity ExtractEntity&lt;TEntity&gt;(Dictionary&lt;string, string&gt; row)  where TEntity : class
  {
      var entity = Activator.CreateInstance&lt;TEntity&gt;();
      var entityType = typeof(TEntity);
  
      foreach (var info in entityType.GetProperties())
      {
          try
          {
              info.SetValue(
                  entity,
                  Convert.ChangeType(row[info.Name], info.PropertyType, CultureInfo.InvariantCulture),
                  null);
          }
          catch {}
      }
  
      return entity;
  }
  </code></pre>
  
  <p>Basically it enumerates a given TEntity and for each public field it obtains the dictionary's item by its key and attempts to convert it to the field's underlying type. It is working well except for bools.</p>