From 1356f9c9211315819f4c86f7cb8321049b0e9ef1 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 24 Feb 2015 17:55:18 -0500 Subject: [PATCH] Add IsBetween extension method --- Extensions/Extensions.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Extensions/Extensions.cs b/Extensions/Extensions.cs index aed5a49..c863ec6 100644 --- a/Extensions/Extensions.cs +++ b/Extensions/Extensions.cs @@ -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(this T item, T start, T end, bool inclusive = false) + { + return inclusive ? + Comparer.Default.Compare(item, start) >= 0 && Comparer.Default.Compare(item, end) <= 0 : + Comparer.Default.Compare(item, start) > 0 && Comparer.Default.Compare(item, end) < 0; + } } }