SideExtensions.cs 2.0 KB

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