Generics Question

I am just starting to work a bit with generics and ran into a little snag. I have a list object that inherits from bindinglist and I implemented a constraint of LabeledRowCollection. The code looks like this:

public abstract class ItemList<T> : BindingList<T> where T : LabeledRowCollection, new()

What I am trying to do now is have ItemList implement the IBindingListView Interface, but I can't get it to work. If I try:

public abstract class ItemList<T> : IBindingListView, BindingList<T> where T : LabeledRowCollection, new()

I get a compile error that says the BindingList declaration must be before all interfaces.

If I change it to the following:

public abstract class ItemList<T> : BindingList<T> where T : LabeledRowCollection, IBindingListView, new()

I then get a compile error because the classes that derive from ItemList don't implement IBindingListView.

What am I doing wrong



Answer this question

Generics Question

  • PawelWasilewski

    doh! Thanks for helping me get past my blonde moment...


  • jreyes97

    How about:

    public abstract class ItemList<T> : BindingList<T>, IBindingListView where T : LabeledRowCollection, new()

    I think that should work - you put all the details about the "main" type first, then all the constraints about the parameterised types.

    Jon



  • Generics Question