具有两个通用类型的继承

时间:2018-07-28 09:40:34

标签: c#

如何使以下内容起作用。第public class DeleteCommandBase<T> where T:ViewModelBase, ICommand行给我一个错误:

  

T:具有通用类型'ViewModelBase'的ViewModelBase需要1种类型   论点

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();
}

1 个答案:

答案 0 :(得分:2)

ViewModelBase<T>是泛型类,如果不指定类型就不能使用它。

不能100%确定您要做什么,但是也许您可以这样做:

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

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