Reputation: 3829
Basically I have a method with the following signature:
public void Save(BindingList<T> items);
and I'm trying to call it using
classInstance.Save(items); //items = BindingList<ObjectInheritedFromT>
but it seems that C# doesn't realize the inheritance throwing a compile-time error, where all code written for T
would be completely functional for ObjectInheritedFromT
as well, wouldn't it?.
Is there a work around for this? I realized this works if it were IEnumerable
, but then (oddly enough) it turns out BindingList<>
doesn't implement IEnumerable, and I need to perform operations such as Remove
and Add
.
Upvotes: 2
Views: 372
Reputation: 16904
Because BindingList<T>
isn't declared as BindingList<out T>
- it doesn't support covariance
Give this a read:
Covariance and Contravariance FAQ
Upvotes: 3