Create an interface that inherits all of your ViewModels CRUD, and your shared ViewModel uses an interface to perform CRUD operations
Here is an example of how the interface and classes might look:
// Generic interface public interface IGenericViewModel { bool Add(); bool Save(); bool Delete(); } // Generic CRUD ViewModel public class GenericViewModel { public IGenericViewModel ObjectViewModel { get; set; } public RelayCommand AddCommand { get ; } public RelayCommand SaveCommand { get ; } public RelayCommand DeleteCommand { get ; } void Add() { ObjectViewModel.Add(); } void Save() { ObjectViewModel.Save(); } void Delete() { ObjectViewModel.Delete(); } } // Specific object ViewModel used by generic CRUD ViewModel public class CustomerViewModel : ViewModelBase, IGenericViewModel { bool IGenericViewModel.Add() { // Add logic } bool IGenericViewModel.Save() { // Save logic } bool IGenericViewModel.Delete() { // Delete object } }
source share