I am wondering how to apply a specific filter to a class declaration in order to only accept certain data types.
Say I want the following two classes:
// Here, T can only be an array type. ie. int[], uint[], byte[], etc.
public class myClassArray<T> where T is Array
{
}
// Here, T can only be an integral numeric type. ie. int, uint, byte, etc.
public class myClassNotArray<T> where T is NotAnArray
{
}
In both cases I still want to be able to do basic arithmetic.
I have tried a bunch of things, but everything failed pretty badly. I think it is because I do not really understand what characterises a specific data type and how to find out what does.
For instance and Array seems to implement:
"ICloneable, System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable"
but somehow, doing something of the sort still does not allow me to do arithmetic:
public class myClassArray<T> where T : ICloneable, System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
{
public voidDoSomeStuff(T value1, T value2)
{
// I would like this to work:
for (int idx = 0; idx < value1.Count(); idx++)
{
var result = value1[idx] - value2[idx];
.....
}
}
}