AlignmentModesExtensions.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.AlignmentModes"/> <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 AlignmentModesExtensions
  14. {
  15. /// <summary>
  16. /// Directly converts this <see cref="Terminal.Gui.AlignmentModes"/> value to an <see langword="int"/> value with the
  17. /// same binary representation.
  18. /// </summary>
  19. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  20. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  21. public static int AsInt32 (this AlignmentModes e) => Unsafe.As<AlignmentModes, int> (ref e);
  22. /// <summary>
  23. /// Directly converts this <see cref="Terminal.Gui.AlignmentModes"/> value to a <see langword="uint"/> value with the
  24. /// same binary representation.
  25. /// </summary>
  26. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  27. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  28. public static uint AsUInt32 (this AlignmentModes e) => Unsafe.As<AlignmentModes, uint> (ref e);
  29. /// <summary>
  30. /// Determines if the specified flags are set in the current value of this
  31. /// <see cref="Terminal.Gui.AlignmentModes"/>.
  32. /// </summary>
  33. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  34. /// <returns>
  35. /// True, if all flags present in <paramref name="checkFlags"/> are also present in the current value of the
  36. /// <see cref="Terminal.Gui.AlignmentModes"/>.<br/>Otherwise false.
  37. /// </returns>
  38. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  39. public static bool FastHasFlags (this AlignmentModes e, AlignmentModes checkFlags)
  40. {
  41. ref uint enumCurrentValueRef = ref Unsafe.As<AlignmentModes, uint> (ref e);
  42. ref uint checkFlagsValueRef = ref Unsafe.As<AlignmentModes, uint> (ref checkFlags);
  43. return (enumCurrentValueRef & checkFlagsValueRef) == checkFlagsValueRef;
  44. }
  45. /// <summary>
  46. /// Determines if the specified mask bits are set in the current value of this
  47. /// <see cref="Terminal.Gui.AlignmentModes"/>.
  48. /// </summary>
  49. /// <param name="e">The <see cref="Terminal.Gui.AlignmentModes"/> value to check against the <paramref name="mask"/> value.</param>
  50. /// <param name="mask">A mask to apply to the current value.</param>
  51. /// <returns>
  52. /// True, if all bits set to 1 in the mask are also set to 1 in the current value of the
  53. /// <see cref="Terminal.Gui.AlignmentModes"/>.<br/>Otherwise false.
  54. /// </returns>
  55. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  56. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  57. public static bool FastHasFlags (this AlignmentModes e, int mask)
  58. {
  59. ref int enumCurrentValueRef = ref Unsafe.As<AlignmentModes, int> (ref e);
  60. return (enumCurrentValueRef & mask) == mask;
  61. }
  62. /// <summary>
  63. /// Determines if the specified <see langword="int"/> value is explicitly defined as a named value of the
  64. /// <see cref="Terminal.Gui.AlignmentModes"/> <see langword="enum"/> type.
  65. /// </summary>
  66. /// <remarks>
  67. /// Only explicitly named values return true, as with IsDefined. Combined valid flag values of flags enums which are
  68. /// not explicitly named will return false.
  69. /// </remarks>
  70. public static bool FastIsDefined (this AlignmentModes _, int value)
  71. {
  72. return value switch
  73. {
  74. 0 => true,
  75. 1 => true,
  76. 2 => true,
  77. 4 => true,
  78. _ => false
  79. };
  80. }
  81. }