Created
March 26, 2009 13:56
-
-
Save alassek/86108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static bool IsNumeric(this String value) | |
{ | |
return Regex.IsMatch(value, @"^\d+$"); | |
} | |
public static string Numeric(this string value) | |
{ | |
return Regex.Replace(value, "\\D", String.Empty); | |
} | |
public static IEnumerable<Control> All(this ControlCollection controls) | |
{ | |
foreach (Control control in controls) { | |
foreach (Control grandchild in control.Controls) { | |
yield return grandchild; | |
} | |
yield return control; | |
} | |
} | |
public static bool TryParse<T>(this Enum e, string value, out T result) | |
{ | |
return TryParse<T>(e, value, out result, false); | |
} | |
public static bool TryParse<T>(this Enum e, string value, out T result, bool ignoreCase) | |
{ | |
try { | |
result = (T) Enum.Parse(typeof(T), value, ignoreCase); | |
return true; | |
} | |
catch { | |
result = default(T); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment