Skip to content

Commit 9f167be

Browse files
fix bug
1 parent f23be16 commit 9f167be

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/Reflector/Is.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace VReflector;
55

66
public static class Is
77
{
8+
public static bool InRange<T>([DisallowNull] T comparable, T? from, T? to)
9+
where T : IComparable<T> =>
10+
comparable.CompareTo(from) >= 0 &&
11+
comparable.CompareTo(to) <= 0;
812
public static Type? GetType(object? obj) => obj?.GetType();
913
public static Type GetType<T>() => typeof(T);
10-
public static bool InRange<T>([DisallowNull] T comparable, T? from, T? to)
11-
where T : IComparable<T> =>
12-
comparable.CompareTo(from) >= 0 &&
13-
comparable.CompareTo(to) <= 0;
1414
public static bool Same(object? actual, object? expected)
1515
{
1616
if (actual == null && expected == null)

src/Reflector/IsNumerics.cs

+20-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace VReflector;
66

77
public static class IsNumerics
88
{
9+
public static bool InRange<T>([DisallowNull] T comparable, T? from, T? to)
10+
where T : IComparable<T> =>
11+
comparable.CompareTo(from) >= 0 &&
12+
comparable.CompareTo(to) <= 0;
913
public static bool NumericType([NotNullWhen(true)] object? obj)
1014
{
1115
return obj is double or float or byte or sbyte or decimal or int or uint or long or ulong or short or ushort or Half;
@@ -109,22 +113,18 @@ public static bool GreaterThan<T>(T a, T b) where T : INumber<T>, IComparable<T>
109113
{
110114
return a?.CompareTo(b) > 0;
111115
}
112-
113116
public static bool LessThan<T>(T a, T b) where T : INumber<T>, IComparable<T>
114117
{
115118
return a?.CompareTo(b) < 0;
116119
}
117-
118120
public static bool GreaterThanOrEqual<T>(T a, T b) where T : INumber<T>, IComparable<T>
119121
{
120122
return a?.CompareTo(b) >= 0;
121123
}
122-
123124
public static bool LessThanOrEqual<T>(T a, T b) where T : INumber<T>, IComparable<T>
124125
{
125126
return a?.CompareTo(b) <= 0;
126127
}
127-
128128
public static bool AreEqual<T>(T a, T b) where T : INumber<T>, IComparable<T>
129129
{
130130
return a?.CompareTo(b) == 0;
@@ -268,13 +268,25 @@ public static bool IsInfinity<T>(T value) where T : INumber<T>
268268
}
269269
return false;
270270
}
271-
public static bool IsZero<T>(T value) where T : INumber<T>
271+
public static bool IsPositive<T>(T value) where T : INumber<T>, IComparable<T>
272+
{
273+
return value?.CompareTo(T.Zero) > 0;
274+
}
275+
public static bool IsNegative<T>(T value) where T : INumber<T>, IComparable<T>
276+
{
277+
return value?.CompareTo(T.Zero) < 0;
278+
}
279+
public static bool IsZero<T>(T value) where T : INumber<T>, IComparable<T>
280+
{
281+
return value?.CompareTo(T.Zero) == 0;
282+
}
283+
public static bool IsPositiveOrZero<T>(T value) where T : INumber<T>, IComparable<T>
272284
{
273-
return value == T.Zero;
285+
return value?.CompareTo(T.Zero) >= 0;
274286
}
275-
public static T Negate<T>(T value) where T : INumber<T>
287+
public static bool IsNegativeOrZero<T>(T value) where T : INumber<T>, IComparable<T>
276288
{
277-
return -value;
289+
return value?.CompareTo(T.Zero) <= 0;
278290
}
279291
public static T GCD<T>(T a, T b) where T : INumber<T>
280292
{

0 commit comments

Comments
 (0)