BorderSettingsExtensions.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.BorderSettings"/> <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 BorderSettingsExtensions
  14. {
  15. /// <summary>
  16. /// Directly converts this <see cref="Terminal.Gui.BorderSettings"/> 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 BorderSettings e) => Unsafe.As<BorderSettings, int> (ref e);
  22. /// <summary>
  23. /// Directly converts this <see cref="Terminal.Gui.BorderSettings"/> 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 BorderSettings e) => Unsafe.As<BorderSettings, uint> (ref e);
  29. /// <summary>
  30. /// Determines if the specified flags are set in the current value of this
  31. /// <see cref="Terminal.Gui.BorderSettings"/>.
  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.BorderSettings"/>.<br/>Otherwise false.
  37. /// </returns>
  38. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  39. public static bool FastHasFlags (this BorderSettings e, BorderSettings checkFlags)
  40. {
  41. ref uint enumCurrentValueRef = ref Unsafe.As<BorderSettings, uint> (ref e);
  42. ref uint checkFlagsValueRef = ref Unsafe.As<BorderSettings, 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.BorderSettings"/>.
  48. /// </summary>
  49. /// <param name="e">The <see cref="Terminal.Gui.BorderSettings"/> 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.BorderSettings"/>.<br/>Otherwise false.
  54. /// </returns>
  55. /// <remarks>NO VALIDATION IS PERFORMED!</remarks>
  56. [MethodImpl (MethodImplOptions.AggressiveInlining)]
  57. public static bool FastHasFlags (this BorderSettings e, int mask)
  58. {
  59. ref int enumCurrentValueRef = ref Unsafe.As<BorderSettings, 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.BorderSettings"/> <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 BorderSettings _, int value)
  71. {
  72. return value switch
  73. {
  74. 0 => true,
  75. 1 => true,
  76. 2 => true,
  77. _ => false
  78. };
  79. }
  80. }