Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Common / Range.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Multimedia
20 {
21     /// <summary>
22     /// Represents a range(min, max) value.
23     /// </summary>
24     /// <since_tizen> 3 </since_tizen>
25     public struct Range
26     {
27         /// <summary>
28         /// Initializes a new instance of the range with the specified values.
29         /// </summary>
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)
35         {
36             if (min > max)
37             {
38                 throw new ArgumentException($"min can't be greater than max.");
39             }
40             Min = min;
41             Max = max;
42         }
43
44         /// <summary>
45         /// Gets or sets the minimum value of the range.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         public int Min
49         {
50             get;
51             set;
52         }
53
54         /// <summary>
55         /// Gets or sets the maximum value of the range.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         public int Max
59         {
60             get;
61             set;
62         }
63
64         /// <summary>
65         /// Gets the length of the range.
66         /// </summary>
67         /// <since_tizen> 3 </since_tizen>
68         public int Length => Max - Min;
69
70         /// <summary>
71         /// Determines if the specified value is within the range.
72         /// </summary>
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)
77         {
78             return Min <= value && value <= Max;
79         }
80
81         /// <summary>
82         /// Returns a string that represents the current object.
83         /// </summary>
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()}";
87
88         /// <summary>
89         /// Gets the hash code for this instance of <see cref="Range"/>.
90         /// </summary>
91         /// <returns>The hash code for this instance of <see cref="Range"/>.</returns>
92         /// <since_tizen> 3 </since_tizen>
93         public override int GetHashCode()
94         {
95             return new { Min, Max }.GetHashCode();
96         }
97
98         /// <summary>
99         /// Compares an object to an instance of <see cref="Range"/> for equality.
100         /// </summary>
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)
105         {
106             return obj is Range && this == (Range)obj;
107         }
108
109         /// <summary>
110         /// Compares two instances of <see cref="Range"/> for equality.
111         /// </summary>
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)
117         {
118             return range1.Min == range2.Min && range1.Max == range2.Max;
119         }
120
121         /// <summary>
122         /// Compares two instances of <see cref="Range"/> for inequality.
123         /// </summary>
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)
129         {
130             return !(range1 == range2);
131         }
132     }
133 }
134