guneysus
5/25/2016 - 3:36 PM

ToEnum Extension Method

ToEnum Extension Method

    namespace Extensions {
        static public class Extensions {

            static public T ToEnum<T>(this object value) {
                var result = (T) System.Enum.ToObject(typeof(T), value); 
                return (T)result;
            }

            static public T ToEnum<T>(this string value) {
                var result  = System.Enum.Parse(typeof(T), value);
                return (T)result;
            }

        }
    }