具有处理序列化能力的集合存储库实现
我有几个集合,它们看起来都一样,但对不同类型的集合项进行操作,如下所示:
[CollectionDataContract(ItemName = "Culture")]
public sealed class Cultures : List<LangCult>
{
}
这里重要的代码是 CollectionDataContract
属性,它允许我们将此集合序列化为 XML 文件DataContractSerializer
。整个集合被序列化为一个 XML 文件,该文件以集合类类型的名称命名,例如 Cultures.xml
我想提出一个存储库,精确地带有存储库的接口,这适用于所有可能的集合,例如 public class Slugs : List
我尝试过这样的事情,但我不知道这是否是最好的选择:
public interface ICollectionsRepository<T> where T : IEnumerable
你的想法是什么?
请不要回复有关如何序列化的说明,因为这不是这里的问题,而且我已经可以正常工作了。
I have several collections that all look the same but operate on different types of collection items, like this:
[CollectionDataContract(ItemName = "Culture")]
public sealed class Cultures : List<LangCult>
{
}
The important piece of code here is the CollectionDataContract
attribute which allows us to serialize this collection into an XML file with DataContractSerializer
. The entire collection is serialized into one XML file named as the name of the type of collection class, for instance Cultures.xml
I would like to come up with a repository, precisely with an interface for a repository, that would work on all of the possible collections, for instance public class Slugs : List<string>
.
I tried something like this, but I don't know whether it's the best option:
public interface ICollectionsRepository<T> where T : IEnumerable
Your thoughts?
Please do not respond with instructions on how to serialize because that is not the issue here and I have it working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许我应该说我想要一个带有通用项目的通用集合的接口,其中项目具有公共基类。这就是我解决这个问题的方法,希望有一天有人会发现它有用。
Maybe I should've said I wanted an interface for generic collection with generic items where items have a common base class. This is how I solved it and hopefully someone one day finds it useful.