DimensionExtensions.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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="Dimension"/> <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. public static class DimensionExtensions
  12. {
  13. /// <summary>
  14. /// Directly converts this <see cref="Dimension"/> value to an <see langword="int"/> value with the same
  15. /// binary representation.
  16. /// </summary>
  17. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  18. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  19. public static int AsInt32 (this Dimension e) => Unsafe.As<Dimension, int> (ref e);
  20. /// <summary>
  21. /// Directly converts this <see cref="Dimension"/> value to a <see langword="uint"/> value with the same
  22. /// binary representation.
  23. /// </summary>
  24. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  25. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  26. public static uint AsUInt32 (this Dimension e) => Unsafe.As<Dimension, uint> (ref e);
  27. /// <summary>
  28. /// Determines if the specified <see langword="int"/> value is explicitly defined as a named value of the
  29. /// <see cref="Dimension"/> <see langword="enum"/> type.
  30. /// </summary>
  31. /// <remarks>
  32. /// Only explicitly named values return true, as with IsDefined. Combined valid flag values of flags enums which are
  33. /// not explicitly named will return false.
  34. /// </remarks>
  35. public static bool FastIsDefined (this Dimension _, int value)
  36. {
  37. return value switch
  38. {
  39. 0 => true,
  40. 1 => true,
  41. 2 => true,
  42. _ => false
  43. };
  44. }
  45. }