DimAutoStyleExtensions.cs 3.6 KB

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