O
O.B.
I'm trying to write an operation that sums the hash codes for object
that "may" be a generic list. Obviously the code below does not
compile. But it gets the point across of what I'm trying to
accomplish. Is there a way to cast the object to a List<>?
public int GetHashCodeSum(Object obj)
{
int rv = 0;
if (obj.GetType().IsGenericType &&
obj.GetType().GetGenericTypeDefinition() == typeof(List<>))
{
foreach(Object item in ((List<>)obj).ToArray())
{
rv += item.GetHashCode();
}
}
else
{
rv = obj.GetHashCode();
}
return rv;
}
that "may" be a generic list. Obviously the code below does not
compile. But it gets the point across of what I'm trying to
accomplish. Is there a way to cast the object to a List<>?
public int GetHashCodeSum(Object obj)
{
int rv = 0;
if (obj.GetType().IsGenericType &&
obj.GetType().GetGenericTypeDefinition() == typeof(List<>))
{
foreach(Object item in ((List<>)obj).ToArray())
{
rv += item.GetHashCode();
}
}
else
{
rv = obj.GetHashCode();
}
return rv;
}