Add IsBetween extension method

This commit is contained in:
2015-02-24 17:55:18 -05:00
parent cc0f4c193e
commit 1356f9c921

View File

@@ -1,4 +1,5 @@
using System.IO; using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Json; using System.Runtime.Serialization.Json;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -41,5 +42,12 @@ namespace Common.Extensions
return default(T); 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;
}
} }
} }