public bool EnsureValid(object value)
{
int count = -1;
// check for collections.
ICollection collection = value as ICollection;
if (collection != null)
{
count = collection.Count;
}
else
{
// check for arrays.
Array array = value as Array;
if (array != null)
{
count = array.Length;
}
}
// ensure bounds are less than count.
return EnsureValid(count);
}