自定义数据集,例如通用列表的容器
如果我想创建一个像数据集这样的自定义容器来在其中放置多个通用列表,我该怎么办?
在数据集中,我们可以放置一些具有不同列和行的数据表。通用列表是否可能?
谢谢
if I want to create a custom container like dataset for placing multiple generic lists in it what can I do?
in dataset we can place some datatable with different columns and rows.is it possible for generic lists?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,只要每种类型都可以序列化为 XML,那么您就可以将其存储在 DataSet 中。对于每个列表,您可以将新的数据表添加到数据集中。然后,您可以将存储列表项属性所需的任何列添加到表中。
使用反射来构建通用函数来检查通用列表并根据存储在那里的类型构建一个表并不会太困难。最终结果将是一个包含 1 个到多个表的数据集对象,每个表代表通用列表的内容。您需要记住将要存储的 typeName 存储为数据表的属性。
注意:你的陈述对我来说有点令人困惑,我担心翻译中会丢失一些东西
如果你想要做的是创建一些
list
Yes, as long as each type can be serialized to XML then you can store it in a DataSet. For each list you can add a new datatable to the dataset. You may then add whatever columns to the table you need to store your list item properties.
It would not be too difficult to use reflection to build a generic function to examine your generic list and build a table based on type being stored there. The end result would a single dataset object with 1 to many tables, each representing the contents of a generic list. You will want to remember to store, probably as an attribute of the datatable the typeName being stored.
note: your statement is a bit confusing to me, I am concerned something is lost in translation
If what you are trying to do is create something
list<object> NimasList = new list<object>();
and then store divergent types in a single generic list, your serialization and deserialization just got more complex, but it is still achievable.