ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ToEnum

Parse a string value to the given Enum

Source

using System;
using System.Diagnostics;

internal static class StringExtensions
{
    public static T ToEnum<T>(this string value)
        where T : struct
    {
        Debug.Assert(!string.IsNullOrEmpty(value));
        return (T)Enum.Parse(typeof(T), value, true);
    }
}

Example

todo

Author: unkown

Submitted on: 8 dec. 2007

Language: C#

Type: System.String

Views: 7902