DimensionExtensions.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.Dimension"/> <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. public static class DimensionExtensions
  13. {
  14. /// <summary>
  15. /// Directly converts this <see cref="Terminal.Gui.Dimension"/> value to an <see langword="int"/> value with the same
  16. /// binary representation.
  17. /// </summary>
  18. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  19. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  20. public static int AsInt32 (this Dimension e) => Unsafe.As<Dimension, int> (ref e);
  21. /// <summary>
  22. /// Directly converts this <see cref="Terminal.Gui.Dimension"/> value to a <see langword="uint"/> value with the same
  23. /// binary representation.
  24. /// </summary>
  25. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  26. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  27. public static uint AsUInt32 (this Dimension e) => Unsafe.As<Dimension, 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="Terminal.Gui.Dimension"/> <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 Dimension _, int value)
  37. {
  38. return value switch
  39. {
  40. 0 => true,
  41. 1 => true,
  42. 2 => true,
  43. _ => false
  44. };
  45. }
  46. }