namespace VideoBrowser.Common { using System; using VideoBrowser.If; /// /// Defines the /// public struct RangeInt : IRange { /// /// Initializes a new instance of the class. /// /// The start /// The end /// The allowInvert public RangeInt(int start, int end, bool allowInvert = false) { if (!allowInvert && start > end) { throw new ArgumentException($"{nameof(start)} is equal or greater than {nameof(end)}"); } this.Start = start; this.End = end; } /// /// Gets the End /// public int End { get; } /// /// Gets the Start /// public int Start { get; } /// /// The Equals /// /// The other /// The public bool Equals(IRange other) { return Equals(this.Start, other.Start) && Equals(this.End, other.End); } /// /// The Equals /// /// The /// The public override bool Equals(object obj) { if (!(obj is RangeInt)) { return false; } return this == (RangeInt)obj; } /// Equalses the specified other. /// The other. public bool Equals(RangeInt other) { return this.Start == other.Start && this.End == other.End; } /// /// The GetHashCode /// /// The public override int GetHashCode() { var startHash = this.Start.GetHashCode(); var endHash = this.End.GetHashCode(); return startHash ^ (startHash << 8) ^ endHash ^ (endHash << 4); } /// /// The ToString /// /// The public override string ToString() { return $"Start:{this.Start};End:{this.End};Length:{this.End - this.Start}"; } /// /// Implements the operator ==. /// /// The left. /// The right. /// The result of the operator. public static bool operator ==(RangeInt left, RangeInt right) { return left.Start == right.Start && left.End == right.End; } /// /// Implements the operator !=. /// /// The left. /// The right. /// The result of the operator. public static bool operator !=(RangeInt left, RangeInt right) { return !(left == right); } } }