public static TEnum ParseStringToEnum<TEnum>(this string dataToMatch, bool ignorecase = default(bool))If anyone wants to download it please visit here. The code is part of the StringExtensions class.
where TEnum : struct { return dataToMatch.IsItemInEnum<TEnum>()() ? default(TEnum) : (TEnum)Enum.Parse(typeof(TEnum), dataToMatch, default(bool)); } public static Func<bool> IsItemInEnum<TEnum>(this string dataToCheck) where TEnum : struct { return () => { return string.IsNullOrEmpty(dataToCheck) || !Enum.IsDefined(typeof(TEnum), dataToCheck); }; }
Improvement of Generic Enum Parser and .NET Extensions Methods Library for C# and VB.NET
I updated the previous code about Generic Enum Parser. That code is I include into the .NET Extensions Methods Library for C# and VB.NET project in the Codeplex. The code is below,
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment