H
Hans-Jürgen Philippi
Hi all,
i've written a generic class (using VS 2005 and .NET 2.0) with a T type
parameter and a constraint (naming an interface):
public class MyGenericClass<T> where T : IMyBaseType {
...
}
Inside this class I'm going to call an external function that expects a
parameter with types implementing IMyBaseType:
[a] myFunction(IMyBaseType SingleValue) {...}
and an overload:
myFunction(IMyBaseType[] ArrayValue) {...}
Assuming myItem is of type T and myItems of type T[], thereby I have calls
inside the class that look like this:
[a] myFunction(myItem)
or
myFunction(myItems)
The point is that [a] works but doesn't, the compiler says he "cannot
convert from T[] to IMyBaseType". Obviously he doesn't event recognize that
actually a handling of/conversion to IMyBaseType[] was required resp. the
second overload is meant...
I think I've seen this before and it may have something to do with the
boxing related to the array handling - but I'm not sure how to circumvent
this.
Any ideas?
Greetings,
Hans
i've written a generic class (using VS 2005 and .NET 2.0) with a T type
parameter and a constraint (naming an interface):
public class MyGenericClass<T> where T : IMyBaseType {
...
}
Inside this class I'm going to call an external function that expects a
parameter with types implementing IMyBaseType:
[a] myFunction(IMyBaseType SingleValue) {...}
and an overload:
myFunction(IMyBaseType[] ArrayValue) {...}
Assuming myItem is of type T and myItems of type T[], thereby I have calls
inside the class that look like this:
[a] myFunction(myItem)
or
myFunction(myItems)
The point is that [a] works but doesn't, the compiler says he "cannot
convert from T[] to IMyBaseType". Obviously he doesn't event recognize that
actually a handling of/conversion to IMyBaseType[] was required resp. the
second overload is meant...
I think I've seen this before and it may have something to do with the
boxing related to the array handling - but I'm not sure how to circumvent
this.
Any ideas?
Greetings,
Hans