title: Get datatype from values passed as string
body: <p>I am writing a framework that will connect to many different data source types and return values from these sources. The easy ones are SQL, Access and Oracle. The tougher ones are Sharepoint, CSV. </p>
  
  <p>If I return values from text based sources, I would like to determine the datatype of the data.</p>
  
  <p>Since a CSV is all text, there is no metadata to interrogate, I would need to parse the data somehow to determine the data type.</p>
  
  <p>Example:    </p>
  
  <blockquote>
    <p>List of "true", "true", "false", "false" would be boolean<br>
    List of "1", "0", "1", "0" would be boolean<br>
    List of "1", "4", "-10", "500" would be integer<br>
    List of "15.2", "2015.5896", "1.0245", "500" would be double<br>
    List of "2001/01/01", "2010/05/29 12:00", "1989/12/25 10:34:21" would be datetime</p>
  </blockquote>
  
  <p>It is based on <a href="https://stackoverflow.com/questions/606365/c-doubt-finding-the-datatype/606381#606381" title="similiar question">https://stackoverflow.com/questions/606365/c-doubt-finding-the-datatype/606381#606381</a></p>
  
  <pre><code>object ParseString(string str)
  {
  
     Int32 intValue;
     Int64 bigintValue;
     double doubleValue;
     bool boolValue;
     DateTime dateValue;        
  
  // Place checks higher in if-else statement to give higher priority to type.
  
  if (Int32.TryParse(str, out intValue))
      return intValue;
  else if (Int64.TryParse(str, out bigintValue))
      return bigintValue;
  else if (double.TryParse(str, out doubleValue))
      return doubleValue;       
  else if (bool.TryParse(str, out boolValue))
      return boolValue;
  else if (DateTime.TryParse(str, out dateValue))
      return dateValue;
  else return str;
  
  }
  </code></pre>
  
  <p>Edit: I only need to cater for the following:   </p>
  
  <pre><code>BIT  
  DATETIME  
  INT  
  NVARCHAR(255)  
  NVARCHAR(MAX)  
  BIGINT  
  DECIMAL(36, 17)  
  </code></pre>
  
  <p>Can you see any possible improvement to the priority?</p>