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 a
List types = new List(new Type[] {
typeof(Boolean)
, typeof(int)
, typeof(double)
, typeof(DateTime)
});
string t = "true";
object retu;
foreach (Type type in types)
{
TypeConverter tc = TypeDescriptor.GetConverter(type);
if (tc != null)
{
try
{
object obj = tc.ConvertFromString(t); // your return value;
}
catch (Exception)
{
continue;
}
}
}