Return to Snippet

Revision: 31155
at August 31, 2010 06:09 by wallybh


Initial Code
public class GenericConverter
{
    public static T Parse<T>(string sourceValue) where T : IConvertible
    {
      return (T)Convert.ChangeType(sourceValue, typeof(T));
    }

    public static T Parse<T>(string sourceValue, IFormatProvider provider) where T : IConvertible
    {
      return (T)Convert.ChangeType(sourceValue, typeof(T), provider);
    }
}

Initial URL

                                

Initial Description
Enables to convert types using generics. Simple and clean.

Initial Title
C# Generic Type Conversion

Initial Tags
c

Initial Language
C#