Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Core {
- public static class EnumHelper {
- public static T Parse<T>(string value) {
- return (T)Enum.Parse(typeof(T),value);
- }
- public static T Parse<T>(string value,T defaultValue) {
- return Parse<T>(value,defaultValue,false);
- }
- public static T Parse<T>(string value,T defaultValue,bool ignoreCase) {
- var names = Enum.GetNames(typeof(T));
- if(names.Where(n => n.EqualsIgnoreCase(value)).Count() == 0)
- return defaultValue;
- return (T)Enum.Parse(typeof(T),value,ignoreCase);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment