C# Code Snippets

Submit a Comment

Generic String Parsing

A string can be easily converted into a generic type with the TypeDescriptor class under the System.ComponentModel namespace.

Platform: .NET Framework 4.0

public static T As<T>(this string input)
{
    return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(input);
}

http://stackoverflow.com/questions/2961656/generic-tryparse

 

Back to C# Code Snippet List

Other CSharp Articles

Visual C# Kicks Newsletter
Visual C# Kicks RSS Feed
License Agreement | Privacy Policy
Link to Us | Subscribe to Newsletter | Contact Us