//http://arolibraries.codeplex.com/
//The MIT License (MIT)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AroLibraries.ExtensionMethods.Objects
{
public static class ObjectExt
{
public static bool Ext_In(this T value, IEnumerable values)
{
if (values == null)
throw new ArgumentNullException("values is NULL");
return values.Contains(value);
}
public static T Ext_Limit(this T value, T maximum) where T : IComparable
{
return value.CompareTo(maximum) < 1 ? value : maximum;
}
public static bool Ext_IsBetween(this T me, T lower, T upper) where T : IComparable
{
return me.CompareTo(lower) >= 0 && me.CompareTo(upper) < 0;
}
public static T Ext_GetInRangeValue(this T me, T lower, T upper, T defaultIfLower, T defaultIfUpper) where T : IComparable
{
if (me.CompareTo(lower) >= 0 && me.CompareTo(upper) <= 0)
{
return me;
}
else if (me.CompareTo(lower) < 0)
{
return defaultIfLower;
}
else if (me.CompareTo(upper) > 0)
{
return defaultIfUpper;
}
return default(T);
}
public static T Ext_GetInRangeValue(this T me, T lower, T upper)
where T : IComparable
{
return Ext_GetInRangeValue(me, lower, upper, lower, upper);
}
}
}