将类型列表存储到通用列表 [英] Storing a typed list to a generic list

查看:76
本文介绍了将类型列表存储到通用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我什至不确定这是否可行,但我想问问是否有人在
之前做过这很明智.
我正在使用MVVM在WPF中编写一个接口,最终用户将在此更新使用不同用户控件收集的数据.目的是使用主窗口上的更新按钮同时保存所有更新.

使用调解器,我可以从所有控件中收集所有信息,然后将其检索以进行更新,但是要简化所有事情,只需采用提供所有数据的类型并将更新存储到IT中,然后检索是时候将这些更新移至数据库了.

我可以使用泛型类执行该操作,但是随后我必须按名称将初始类存储到泛型类中.我想做的是将我决定使用的任何类存储到通用列表中.我可以预见,但是我以前从未构建过这种关系.

我要出去吃午饭了吗,或者这是某人做的吗?

I''m not even sure that this is possible, but I thought that it would be smart to ask if anyone has ever done it before

I''m writing an interface in WPF using MVVM where an end user will be updating data which is collected using different user controls. The goal is to save all of the updates at the same time with an update button on the main window.

Using a Mediator, I can collect all of the information from all of the controls and then retrieve it for the update, but what would simplify everything is to just take the type that provided all of the data and store updates to IT, and then retrieve it when it''s time to move these updates to the database.

I can do THAT with a generic class, but then I have to store the initial class by name to the generic class. What I''d like to do is to store whatever class I decide to use to a generic list. I can envision it, but I''ve never constructed that sort of relationship before.

I''m I way out to lunch here or is this something someone has done?

推荐答案

如果我理解正确,那么您所需要做的就是属性使用反射的对象(在本例中为ViewModel).您可以查看以下指示信息:
http://stackoverflow.com/Questions/3610891/c-sharp-copying-property-values-from-one-instance-to-另一个不同的类 [
If I understand you right, then all you need to do is the properties of an object (in this case the ViewModel) using reflection. You can look at the following for direction:
http://stackoverflow.com/questions/3610891/c-sharp-copying-property-values-from-one-instance-to-another-different-classe[^]


这篇关于将类型列表存储到通用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆