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.
24 /// <since_tizen> 3 </since_tizen>
28 /// Initializes a new instance of the range with the specified values.
30 /// <param name="min">Minimum value of the range.</param>
31 /// <param name="max">Maximum value of the range.</param>
32 /// <exception cref="ArgumentException"><paramref name="max"/> is less than <paramref name="min"/>.</exception>
33 /// <since_tizen> 3 </since_tizen>
34 public Range(int min, int max)
38 throw new ArgumentException($"min can't be greater than max.");
45 /// Gets or sets the minimum value of the range.
47 /// <since_tizen> 3 </since_tizen>
55 /// Gets or sets the maximum value of the range.
57 /// <since_tizen> 3 </since_tizen>
65 /// Gets the length of the range.
67 /// <since_tizen> 3 </since_tizen>
68 public int Length => Max - Min;
71 /// Determines if the specified value is within the range.
73 /// <param name="value">The value to check.</param>
74 /// <returns>true if the value is within the range; otherwise false.</returns>
75 /// <since_tizen> 3 </since_tizen>
76 public bool IsInside(int value)
78 return Min <= value && value <= Max;
82 /// Returns a string that represents the current object.
84 /// <returns>A string that represents the current object.</returns>
85 /// <since_tizen> 3 </since_tizen>
86 public override string ToString() => $"Min={Min.ToString()}, Max={Max.ToString()}";
89 /// Gets the hash code for this instance of <see cref="Range"/>.
91 /// <returns>The hash code for this instance of <see cref="Range"/>.</returns>
92 /// <since_tizen> 3 </since_tizen>
93 public override int GetHashCode()
95 return new { Min, Max }.GetHashCode();
99 /// Compares an object to an instance of <see cref="Range"/> for equality.
101 /// <param name="obj">A <see cref="Object"/> to compare.</param>
102 /// <returns>true if the two ranges are equal; otherwise, false.</returns>
103 /// <since_tizen> 3 </since_tizen>
104 public override bool Equals(object obj)
106 return obj is Range && this == (Range)obj;
110 /// Compares two instances of <see cref="Range"/> for equality.
112 /// <param name="range1">A <see cref="Range"/> to compare.</param>
113 /// <param name="range2">A <see cref="Range"/> to compare.</param>
114 /// <returns>true if the two instances of <see cref="Range"/> are equal; otherwise false.</returns>
115 /// <since_tizen> 3 </since_tizen>
116 public static bool operator ==(Range range1, Range range2)
118 return range1.Min == range2.Min && range1.Max == range2.Max;
122 /// Compares two instances of <see cref="Range"/> for inequality.
124 /// <param name="range1">A <see cref="Range"/> to compare.</param>
125 /// <param name="range2">A <see cref="Range"/> to compare.</param>
126 /// <returns>true if the two instances of <see cref="Range"/> are not equal; otherwise false.</returns>
127 /// <since_tizen> 3 </since_tizen>
128 public static bool operator !=(Range range1, Range range2)
130 return !(range1 == range2);