Hello to all,
We've created a generic method like so:
public TReturnType GetValue(string key) { var configurationParameter = (from cp in _repository.ConfigurationParameters where cp.ConfigurationParameterKey == key select cp).FirstOrDefault(); var returnValue (TReturnType)Convert.ChangeType(configurationParameter.ConfigurationParameterValue, typeof (TReturnType)); return returnValue; }
Now, we would like to put some error handling in this method so that in case we're expecting a numeric type we can do, for example, an int.TryParse(returnValue, out myNewInt). Of course to be able to do that we would have to be able to determine the type of TReturnType within the method.
Is there a way to do this?
Thanks for all of your help. Regards.