Is it possible to derive the intended object type from a .NET format string in C#? For example:
//Input parameters
var formatString = "dd/MM/yyyy"; //or "£0.00" for example
var stringValue = "2014-04-01"; //or "37.34" for example
//Logic
object value = null;
if (IsADate(formatString)) {
objectValue = DateTime.Parse(stringValue);
} else if (IsANumber(formatString)) {
objectValue = double.Parse(stringValue);
} else //etc
//Result
var resultString = String.Format(value,formatString);
I could obviously write out the IsADate() and IsANumber() functions, but wondered whether there is anything in the Framework that covers this already?
stringValueor do you really need a function that maps aformatStringto aType?