I'm trying to make a generic method for type conversions which gets an object and the type of object to be cast.
By using Convert.ChangeType()
I can do what I want, but it takes too much time on run time. What is the best method to make a generic class like I want.
My old code looks like that;
public static ConvertTo<T>(object data) where T : struct // yes the worst variable name!
{
// do some controls...
return Convert.ChangeType(data, typeof(T));
}
Edit: To clarify...
For Ex; I've executed my query and it returned a DataRow. And there is a column which typed as decimal which I want to cast to long. If I call this method, it takes so much time to cast decimal to long.
And T type of this method could be only value type. I mean "T : struct"