SideExtensions.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.CodeDom.Compiler;
  2. using System.Diagnostics;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Runtime.CompilerServices;
  5. namespace Terminal.Gui.ViewBase;
  6. /// <summary>Extension methods for the <see cref="Side"/> <see langword="enum"/> type.</summary>
  7. [GeneratedCode ("Terminal.Gui.Analyzers.Internal", "1.0")]
  8. [CompilerGenerated]
  9. [DebuggerNonUserCode]
  10. [ExcludeFromCodeCoverage (Justification = "Generated code is already tested.")]
  11. [PublicAPI]
  12. public static class SideExtensions
  13. {
  14. /// <summary>
  15. /// Directly converts this <see cref="Side"/> value to an <see langword="int"/> value with the same binary
  16. /// representation.
  17. /// </summary>
  18. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  19. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  20. public static int AsInt32 (this Side e) => Unsafe.As<Side, int> (ref e);
  21. /// <summary>
  22. /// Directly converts this <see cref="Side"/> value to a <see langword="uint"/> value with the same binary
  23. /// representation.
  24. /// </summary>
  25. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  26. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  27. public static uint AsUInt32 (this Side e) => Unsafe.As<Side, uint> (ref e);
  28. /// <summary>
  29. /// Determines if the specified <see langword="int"/> value is explicitly defined as a named value of the
  30. /// <see cref="Side"/> <see langword="enum"/> type.
  31. /// </summary>
  32. /// <remarks>
  33. /// Only explicitly named values return true, as with IsDefined. Combined valid flag values of flags enums which are
  34. /// not explicitly named will return false.
  35. /// </remarks>
  36. public static bool FastIsDefined (this Side _, int value)
  37. {
  38. return value switch
  39. {
  40. 0 => true,
  41. 1 => true,
  42. 2 => true,
  43. 3 => true,
  44. _ => false
  45. };
  46. }
  47. }