FlagsHelper.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. namespace WebDAVSharp.Server.Utilities
  2. {
  3. /// <summary>
  4. /// </summary>
  5. public static class FlagsHelper
  6. {
  7. /// <summary>
  8. /// </summary>
  9. /// <typeparam name="T"></typeparam>
  10. /// <param name="flags"></param>
  11. /// <param name="flag"></param>
  12. /// <returns></returns>
  13. public static bool IsSet<T>(T flags, T flag) where T : struct
  14. {
  15. int flagsValue = (int) (object) flags;
  16. int flagValue = (int) (object) flag;
  17. return (flagsValue & flagValue) != 0;
  18. }
  19. /// <summary>
  20. /// </summary>
  21. /// <typeparam name="T"></typeparam>
  22. /// <param name="flags"></param>
  23. /// <param name="flag"></param>
  24. public static void Set<T>(ref T flags, T flag) where T : struct
  25. {
  26. int flagsValue = (int) (object) flags;
  27. int flagValue = (int) (object) flag;
  28. flags = (T) (object) (flagsValue | flagValue);
  29. }
  30. /// <summary>
  31. /// </summary>
  32. /// <typeparam name="T"></typeparam>
  33. /// <param name="flags"></param>
  34. /// <param name="flag"></param>
  35. public static void Unset<T>(ref T flags, T flag) where T : struct
  36. {
  37. int flagsValue = (int) (object) flags;
  38. int flagValue = (int) (object) flag;
  39. flags = (T) (object) (flagsValue & (~flagValue));
  40. }
  41. }
  42. }