I'm doing and WPF application and I have a ViewModel that I use in several Views and in DataGrids.
Now I have another View that requires an extended or decorated version of that ViewModel. So I decided to go for inheritance in this way:
public class StandardViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class ExtendedViewModel : StandardViewModel
{
public string Email { get; set; }
}
However, I want to decorate and existing instance of the StandardViewModel
. Specifically the selected object in the DataGrid so it can be passed into the other View.
The new View needs access to the properties of both classes (the Email
and the FirtsName
and LastName
)
So I'm thinking of ways to creating a constructor for my ExtendedViewModel
.
My idea is to copy the base instance directly.
- Is this correct?
- And efficient?
- Is there any other way of doing it?
public class ExtendedViewModel : StandardViewModel
{
public string Email { get; set; }
public ExtendedViewModel(StandardViewModel base)
{
this = base
}
}
Edit
I'm doing this for not only one but several classes. And they do not have only two properties so I'm trying to avoid copying the values one by one.