AlignmentModesExtensions.cs 3.7 KB

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