Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Something(this Enum e)
- {
- // code here
- }
- public static void EnumExtension(this Enum e)
- {
- }
- <Extension()> _
- Public Sub EnumExtension(ByVal s As Enum)
- End Sub
- public static class ExtensionMethods
- {
- public static bool TryParse<T>(this Enum theEnum, string strType,
- out T result)
- {
- string strTypeFixed = strType.Replace(' ', '_');
- if (Enum.IsDefined(typeof(T), strTypeFixed))
- {
- result = (T)Enum.Parse(typeof(T), strTypeFixed, true);
- return true;
- }
- else
- {
- foreach (string value in Enum.GetNames(typeof(T)))
- {
- if (value.Equals(strTypeFixed,
- StringComparison.OrdinalIgnoreCase))
- {
- result = (T)Enum.Parse(typeof(T), value);
- return true;
- }
- }
- result = default(T);
- return false;
- }
- }
- }
- public enum TestEnum
- {
- A,
- B,
- C
- }
- public void TestMethod(string StringOfEnum)
- {
- TestEnum myEnum;
- myEnum.TryParse(StringOfEnum, out myEnum);
- }
- public enum TestEnum
- {
- A,B,C
- }
- public void TestMethod(string StringOfEnum)
- {
- TestEnum myEnum;
- myEnum.TryParse(StringOfEnum, out myEnum);
- }
- public enum TestEnum
- {
- A,B,C
- }
- public void TestMethod(string StringOfEnum)
- {
- TestEnum myEnum = default(TestEnum);
- myEnum.TryParse(StringOfEnum, out myEnum);
- }
Add Comment
Please, Sign In to add comment