a little while ago i was reading an article about a series of class that were created that handled the conversion of strings into a generic type. Below is a mock class structure. Basically if you set the StringValue it will perform some conversion into type T
public class MyClass<T>
{
public string StringValue {get;set;}
public T Value {get;set;}
}
I cannot remember the article that i was reading, or the name of the class i was reading about. Is this already implemented in the framework? Or shall i create my own?
Here is a little trick to convert strings into simple types (struct types) :
public T GetValueAs<T>(string sValue)
where T : struct
{
if (string.IsNullOrEmpty(sValue))
{
return default(T);
}
else
{
return (T)Convert.ChangeType(sValue, typeof(T));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With