NoKey.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. namespace Quadarax.Foundation.Core.Data.Entity
  3. {
  4. public class NoKey : IEquatable<NoKey>
  5. {
  6. public Guid Hash { get; }
  7. public NoKey()
  8. {
  9. Hash = Guid.NewGuid();
  10. }
  11. public bool Equals(NoKey other)
  12. {
  13. if (other == null)
  14. return false;
  15. return Hash == other.Hash;
  16. }
  17. public override bool Equals(object obj)
  18. {
  19. if (ReferenceEquals(null, obj)) return false;
  20. if (ReferenceEquals(this, obj)) return true;
  21. if (obj.GetType() != this.GetType()) return false;
  22. return Equals((NoKey)obj);
  23. }
  24. public override int GetHashCode()
  25. {
  26. return Hash.GetHashCode();
  27. }
  28. public static bool operator ==(NoKey left, NoKey right)
  29. {
  30. return Equals(left, right);
  31. }
  32. public static bool operator !=(NoKey left, NoKey right)
  33. {
  34. return !Equals(left, right);
  35. }
  36. }
  37. }