mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-13 17:22:40 -05:00
Add IsBetween extension method
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -41,5 +42,12 @@ namespace Common.Extensions
|
||||
return default(T);
|
||||
});
|
||||
}
|
||||
|
||||
public static bool IsBetween<T>(this T item, T start, T end, bool inclusive = false)
|
||||
{
|
||||
return inclusive ?
|
||||
Comparer<T>.Default.Compare(item, start) >= 0 && Comparer<T>.Default.Compare(item, end) <= 0 :
|
||||
Comparer<T>.Default.Compare(item, start) > 0 && Comparer<T>.Default.Compare(item, end) < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user