2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Multimedia
22 /// Represents a range(min, max) value.
27 /// Initializes a new instance of the Range with the specified values.
29 /// <param name="min">Minimum value of the range.</param>
30 /// <param name="max">Maximum value of the range.</param>
31 /// <exception cref="ArgumentException"><paramref name="max"/> is less than <paramref name="min"/>.</exception>
32 public Range(int min, int max)
36 throw new ArgumentException($"min can't be greater than max.");
43 /// Gets or sets minimum value of the range.
52 /// Gets or sets maximum value of the range.
61 /// Gets length of the range.
63 public int Length => Max - Min;
66 /// Determines if the specified value is inside of the range.
68 /// <param name="value">A value to check.</param>
69 /// <returns>true if the value is inside of the range; otherwise false.</returns>
70 public bool IsInside(int value)
72 return Min <= value && value <= Max;
76 /// Returns a string that represents the current object.
78 /// <returns>A string that represents the current object.</returns>
79 public override string ToString() => $"Min={Min.ToString()}, Max={Max.ToString()}";
82 /// Gets the hash code for this instance of <see cref="Range"/>.
84 /// <returns>The hash code for this instance of <see cref="Range"/>.</returns>
85 public override int GetHashCode()
87 return new { Min, Max }.GetHashCode();
91 /// Compares an object to an instance of <see cref="Range"/> for equality.
93 /// <param name="obj">A <see cref="Object"/> to compare.</param>
94 /// <returns>true if the two ranges are equal; otherwise, false.</returns>
95 public override bool Equals(object obj)
97 return obj is Range && this == (Range)obj;
101 /// Compares two instances of <see cref="Range"/> for equality.
103 /// <param name="range1">A <see cref="Range"/> to compare.</param>
104 /// <param name="range2">A <see cref="Range"/> to compare.</param>
105 /// <returns>true if the two instances of <see cref="Range"/> are equal; otherwise false.</returns>
106 public static bool operator ==(Range range1, Range range2)
108 return range1.Min == range2.Min && range1.Max == range2.Max;
112 /// Compares two instances of <see cref="Range"/> for inequality.
114 /// <param name="range1">A <see cref="Range"/> to compare.</param>
115 /// <param name="range2">A <see cref="Range"/> to compare.</param>
116 /// <returns>true if the two instances of <see cref="Range"/> are not equal; otherwise false.</returns>
117 public static bool operator !=(Range range1, Range range2)
119 return !(range1 == range2);