Mister 832
Mister 832

Reputation: 1221

Inheritance with two generic Types

How can I get the following to work. The Line public class DeleteCommandBase<T> where T:ViewModelBase, ICommand gives me an error:

T:ViewModelBase with Generic type 'ViewModelBase' requires 1 type argument

public abstract class ViewModelBase<T> where T : ModelBase, INotifyPropertyChanged
{
    public abstract ICommand DeleteCommand { get; set; }
    public abstract ObservableCollection<T> Records { get; set; }
}
public class DeleteCommandBase<T> where T:ViewModelBase,  ICommand
{
    public T viewModel { get; set; }
    public event EventHandler CanExecuteChanged;

    public DeleteCommandBase(T vm)       => viewModel = vm;
    public bool CanExecute(object param) => true;
    public void Execute(object parame)   => throw new NotImplementedException();
}

Upvotes: 0

Views: 57

Answers (1)

MineR
MineR

Reputation: 2194

ViewModelBase<T> is a generic class, you can't use it without specifying a type.

Not 100% sure what you're trying to do, but perhaps you can do this instead:

public class DeleteCommandBase<T> where T : ModelBase, INotifyPropertyChanged
{
    public ViewModelBase<T> viewModel { get; set; }

    public DeleteCommandBase(ViewModelBase<T> vm) => viewModel = vm;
    ...
}

Upvotes: 2

Related Questions