You don't technically need to. .NET already has this functionality.
For conversions between plain old data types (ints, floats, etc) you can use
Convert.ChangeType. For more complex conversions you might need to
upgrade to TypeConverter. This class is used internally in .NET for
type conversion.
Here's a simple generic method to convert from one type to another. It does
no error checking and will not work for complex types. It will, however,
convert to structure types in most cases.
static TOutput ConvertTo <TInput, TOutput> ( TInput input )
{
Type typeIn = typeof(TInput);
Type typeOut = typeof(TOutput);
if (typeIn.IsPrimitive && typeOut.IsPrimitive)
return (TOutput)Convert.ChangeType(input, typeOut);
TypeConverter conv = TypeDescriptor.GetConverter(typeOut);
return (TOutput)conv.ConvertFrom(input);
}