daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public struct AbonentId : IFormattable, IComparable, IComparable<AbonentId>, IComparable<Guid>, IEquatable<AbonentId>, IEquatable<Guid>
  2. {
  3.     // ReSharper disable once MemberCanBePrivate.Global
  4.     //эта штука нужна чтобы работал сериализвтор
  5.     public Guid Value { get; set; }
  6.  
  7.     #region Casts
  8.  
  9.     public static explicit operator Guid(AbonentId abonentId) => abonentId.Value;
  10.  
  11.     public static explicit operator AbonentId(Guid abonentId) => new AbonentId {Value = abonentId};
  12.  
  13.     #endregion
  14.  
  15.     #region Equatable
  16.  
  17.     public bool Equals(AbonentId other) => Value.Equals(other.Value);
  18.     public bool Equals(Guid other) => Value.Equals(other);
  19.  
  20.     public override int GetHashCode() => Value.GetHashCode();
  21.  
  22.     public override bool Equals(object obj)
  23.     {
  24.         if (ReferenceEquals(null, obj))
  25.         {
  26.             return false;
  27.         }
  28.         return obj is AbonentId && Equals((AbonentId)obj)
  29.             || obj is Guid && Equals((Guid)obj);
  30.     }
  31.  
  32.     public static bool operator ==(AbonentId left, AbonentId right) => left.Equals(right);
  33.     public static bool operator !=(AbonentId left, AbonentId right) => !left.Equals(right);
  34.  
  35.     #endregion
  36.  
  37.     #region Formattable
  38.  
  39.     public string ToString(string format, IFormatProvider formatProvider) => Value.ToString(format, formatProvider);
  40.     public override string ToString() => Value.ToString();
  41.  
  42.     #endregion
  43.  
  44.     #region Comparable
  45.  
  46.     public int CompareTo(AbonentId other) => Value.CompareTo(other.Value);
  47.  
  48.     public int CompareTo(Guid other) => Value.CompareTo(other);
  49.  
  50.     public int CompareTo(object obj)
  51.     {
  52.         var abonentId = obj as AbonentId?;
  53.         return abonentId.HasValue
  54.             ? Value.CompareTo(abonentId.Value.Value)
  55.             : Value.CompareTo(obj);
  56.     }
  57.  
  58.     #endregion
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top