AddOrSubtractExtensions.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.AddOrSubtract"/> <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 AddOrSubtractExtensions
  14. {
  15. /// <summary>
  16. /// Directly converts this <see cref="Terminal.Gui.AddOrSubtract"/> 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 AddOrSubtract e) => Unsafe.As<AddOrSubtract, int> (ref e);
  22. /// <summary>
  23. /// Directly converts this <see cref="Terminal.Gui.AddOrSubtract"/> 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 AddOrSubtract e) => Unsafe.As<AddOrSubtract, uint> (ref e);
  29. /// <summary>
  30. /// Determines if the specified <see langword="int"/> value is explicitly defined as a named value of the
  31. /// <see cref="Terminal.Gui.AddOrSubtract"/> <see langword="enum"/> type.
  32. /// </summary>
  33. /// <remarks>
  34. /// Only explicitly named values return true, as with IsDefined. Combined valid flag values of flags enums which are
  35. /// not explicitly named will return false.
  36. /// </remarks>
  37. public static bool FastIsDefined (this AddOrSubtract _, int value)
  38. {
  39. return value switch
  40. {
  41. 0 => true,
  42. 1 => true,
  43. _ => false
  44. };
  45. }
  46. }