Hi everybody,
when migrating to the .NET 2.0 framework we decided to encourage the use
of generic functions because they ought to run faster than their
equivalent object-implemantations.
Now I have the following problem:
I adapted my common functions to use the generic implementations of the
..NET-classes and interfaces. Now I got problems when calling my
functions with enum-types:
enum TypeOfAction {
Delete = 1,
Copy = 2,
Move = 3,
Cut = 4
}
// Find all entries with specified key and return corresponding values
public static V[] ExtractArrayEntries <T, V>
(T[] keys, V[] values, T key)
{
// next line throws with "Unable to cast ... 'TypeOfAction'
// to 'IComparable<TypeOfAction>'
IComparable<T> comparableValue = (IComparable<T>) key;
[...]
if (comparableValue.CompareTo(keys[i]) == 0) retArray[j] = values[i];
[...]
}
When I use normal int's, it works fine. The old version with the
object-typed version of IComparable also worked fine with Enums.
Is there I special reason I don't see why MS didn't fit the Enum-class
with the IComparable<T>-interface?
Is there a workaround to solve this problem?
TIA,
Stefan