title: C#: Dynamic parse from System.Type
body: <p>I have a Type, a String and an Object.</p>
  
  <p>Is there some way I can call the parse method or convert for that type on the string dynamically?</p>
  
  <p>Basically how do I remove the if statements in this logic</p>
  
  <pre><code>object value = new object();    
  String myString = "something";
  Type propType = p.PropertyType;
  
  if(propType == Type.GetType("DateTime"))
  {
      value = DateTime.Parse(myString);
  }
  
  if (propType == Type.GetType("int"))
  {
      value = int.Parse(myString);
  }
  </code></pre>
  
  <p>And do someting more like this.</p>
  
  <pre><code>object value = new object();
  String myString = "something";
  Type propType = p.PropertyType;
  
  
  //this doesn't actually work
  value = propType .Parse(myString);  
  </code></pre>