BarcodeResult.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Microsoft.Maui.Graphics;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace InABox.Avalonia.Platform.Barcodes;
  8. public class BarcodeResult : IEquatable<BarcodeResult>
  9. {
  10. public required BarcodeTypes BarcodeType { get; init; }
  11. public required BarcodeFormats BarcodeFormat { get; init; }
  12. public required string DisplayValue { get; init; }
  13. public required string RawValue { get; init; }
  14. public required byte[] RawBytes { get; init; }
  15. public required RectF PreviewBoundingBox { get; init; }
  16. public required RectF ImageBoundingBox { get; init; }
  17. public bool Equals(BarcodeResult? other)
  18. {
  19. if (other is null)
  20. return false;
  21. if (!string.IsNullOrEmpty(RawValue))
  22. {
  23. return RawValue == other.RawValue && ImageBoundingBox.IntersectsWith(other.ImageBoundingBox);
  24. }
  25. else
  26. {
  27. return DisplayValue == other.DisplayValue && ImageBoundingBox.IntersectsWith(other.ImageBoundingBox);
  28. }
  29. }
  30. public override bool Equals(object? obj)
  31. {
  32. return obj is BarcodeResult result && Equals(result);
  33. }
  34. public override int GetHashCode()
  35. {
  36. return !string.IsNullOrEmpty(RawValue) ? RawValue.GetHashCode() : DisplayValue.GetHashCode();
  37. }
  38. }