StringUtils.cs 673 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. namespace ExtensionMethods
  3. {
  4. public static class StringUtils
  5. {
  6. public static bool IsInArray(this string value, string[] array)
  7. {
  8. for (int i = 0; i < array.Length; i++)
  9. {
  10. if (value == array[i])
  11. {
  12. return true;
  13. }
  14. }
  15. return false;
  16. }
  17. public static bool IsInEnum<TEnum>(this string value, bool ignoreCase = false) where TEnum : struct, IConvertible
  18. {
  19. return EnumTools.IsInEnum<TEnum>(value, ignoreCase);
  20. }
  21. public static TEnum ToEnum<TEnum>(this string value, bool ignoreCase = false) where TEnum : struct, IConvertible
  22. {
  23. return EnumTools.ToEnum<TEnum>(value, ignoreCase);
  24. }
  25. }
  26. }