- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathComparers.cs
70 lines (61 loc) · 2.76 KB
/
Comparers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
usingSystem;
namespaceAlgorithms.Common
{
publicstaticclassComparers
{
/// <summary>
/// Determines if a specific value is a number.
/// </summary>
/// <returns><c>true</c> if the value is a number; otherwise, <c>false</c>.</returns>
/// <param name="value">Value.</param>
/// <typeparam name="T">The Type of value.</typeparam>
publicstaticboolIsNumber<T>(thisTvalue)
{
if(valueissbyte)returntrue;
if(valueisbyte)returntrue;
if(valueisshort)returntrue;
if(valueisushort)returntrue;
if(valueisint)returntrue;
if(valueisuint)returntrue;
if(valueislong)returntrue;
if(valueisulong)returntrue;
if(valueisfloat)returntrue;
if(valueisdouble)returntrue;
if(valueisdecimal)returntrue;
returnfalse;
}
/// <summary>
/// Determines if firstValue is equals to the specified secondValue.
/// </summary>
/// <returns><c>true</c> if firstValue is equals to the specified secondValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
publicstaticboolIsEqualTo<T>(thisTfirstValue,TsecondValue)whereT:IComparable<T>
{
returnfirstValue.Equals(secondValue);
}
/// <summary>
/// Determines if thisValue is greater than the specified otherValue.
/// </summary>
/// <returns><c>true</c> if thisValue is greater than the specified otherValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
publicstaticboolIsGreaterThan<T>(thisTfirstValue,TsecondValue)whereT:IComparable<T>
{
returnfirstValue.CompareTo(secondValue)>0;
}
/// <summary>
/// Determines if thisValue is less than the specified otherValue.
/// </summary>
/// <returns><c>true</c> if thisValue is less than the specified otherValue; otherwise, <c>false</c>.</returns>
/// <param name="firstValue">The first value.</param>
/// <param name="secondValue">The second value.</param>
/// <typeparam name="T">The Type of values.</typeparam>
publicstaticboolIsLessThan<T>(thisTfirstValue,TsecondValue)whereT:IComparable<T>
{
returnfirstValue.CompareTo(secondValue)<0;
}
}
}