Skip to content

Instantly share code, notes, and snippets.

@alassek
Created March 26, 2009 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alassek/86108 to your computer and use it in GitHub Desktop.
Save alassek/86108 to your computer and use it in GitHub Desktop.
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