title: Formatting a string without knowing the underlying data type
body: <p>I am binding data to a grid. Along with the data, accompanies the format pattern which is to be used to to format the data.</p>
  <pre><code>foreach (ColumnConfiguration colConfig in ColumnConfigDashboard)
    {
       int position = colConfig.Position + 2; 
       string format = colConfig.FormatData; //one of the undermentioned formats
       HtmlGenericControl lblColData = (e.Item.FindControl(&quot;lblBoundData_&quot; + position.ToString())) as HtmlGenericControl;
       string data = drv.Row[colConfig.ColumnName].ToString();
       lblColData.InnerText = string.Format(&quot;{0:&quot; + format + &quot;}&quot;, data);
     }
                      
  </code></pre>
  <p>The problem is while fetching the data, I am getting it as a string and have no way to know whether it was originally a <code>DateTime</code>, a <code>String</code>, a <code>Numeric</code> like <code>int/float/double</code> or something else altogether.</p>
  <p>The format patterns as of now are (but will not be limited to)</p>
  <blockquote>
  <p>hhmm</p>
  <p>mm/dd/yyyy</p>
  <p>24hrtime</p>
  <p>SSN</p>
  <p>{0} {1} {2} {3}</p>
  <p>{3}, {1}</p>
  <p>{1} {3} {2}</p>
  <p>XXX-XX-{5}{6}{7}{8}</p>
  <p>{1}</p>
  <p>d</p>
  <p>D</p>
  <p>t</p>
  </blockquote>
  <p>Now some of these formats are recognized by the .NET framework (<em>like 'd', 'T', mm/dd/yyyy</em>) and some are custom (<em>like SSN</em>).</p>
  <p>Is there a way to identify the base type of the data before the formatting or perform the formatting in a type agnostic manner?</p>