I have this class definition:
public abstract class AbstractListViewModel<T> : AbstractWorkspaceViewModel
So I have a class called AbstractListViewModel that has a generic type, and that is a subclass of AbstractWorkspaceViewModel.
However, I need to constrain T to only be subclasses of AbstractWorkspaceViewModel. I tried the following:
public abstract class AbstractListViewModel<T> where T :
AbstractWorkspaceViewModel, : AbstractWorkspaceViewModel
public abstract class AbstractListViewModel<T> where T :
AbstractWorkspaceViewModel : AbstractWorkspaceViewModel
But this syntax is invalid.
So here I am trying to say “A class called AbstractListViewModel that is a subclass of AbstractWorkspaceViewModel and has a generic type that is also a subclass of AbstractWorkspaceViewModel.
How do I define this?
It’s the ordering of your constraint. Try this: