generate viewmodel from model?

落花浮王杯 提交于 2020-01-02 07:21:12

问题


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 ...


回答1:


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.



回答2:


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



来源:https://stackoverflow.com/questions/1577533/generate-viewmodel-from-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!