generate viewmodel from model?

2019-05-14 02:37发布

I'm currently writing viewmodels for my (WPF/C#) app.

I have to do a lot of copy and paste though. Isn't there a way to generate the viewmodel from the model like generating the model from the database?

I haven't found anything about it on the net ...

2条回答
啃猪蹄的小仙女
2楼-- · 2019-05-14 03:12

Have a look at Karl Shifflet's XAML Power Toys. It's a Visual Studio plugin which includes various helpers for developing WPF or Silverlight applications. One of the features is exactly what you're looking for:

  • Create ViewModel Class - from a VB.NET or C# code window, easily create a ViewModel stub that includes commands and exposed data class. Optionally you can elect to re-implement all Model properties on the ViewModel.
查看更多
Melony?
3楼-- · 2019-05-14 03:26

Maybe have a look at automapper. This would at least save you from manually copying the properties between viewmodel and model.

查看更多
登录 后发表回答