Skip to content

Instantly share code, notes, and snippets.

View dejanstojanovic's full-sized avatar
🎧
Focusing

Dejan Stojanovic dejanstojanovic

🎧
Focusing
View GitHub Profile
@dejanstojanovic
dejanstojanovic / String.ConvertTo
Created February 3, 2015 04:32
Convert string value to C# strong type
/// <summary>
/// Converting the string value to T type
/// </summary>
/// <typeparam name="T">Type to convert string value to</typeparam>
/// <param name="value">String value to be converted to type T</param>
/// <returns>Returns converted string value to type T</returns>
public static T ConvertTo<T>(this string value) where T : IConvertible
{
var typeCode = default(T).GetTypeCode();
switch (typeCode)