使用只读集合缓存对象 [英] caching objects with readonly collections

查看:62
本文介绍了使用只读集合缓存对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试缓存一个包含一些属性的对象以及一个只读集合。

I am trying to Cache a object which contains some Properties along with a readonly collection.

当我后退时来自Cahe的对象,集合变空了。

When i retreive the object from Cahe, collection is becoming empty.

如果我使Collection Property能够读写,我可以在集合中获取Values,但是FxCop会抛出一条错误说make收藏只读。

If I make the Collection Property to read and write, I am able to get the Values inside the collection, However FxCop throws an error saying make the Collections Readonly.

有人建议解决方案吗?

谢谢

A.Suresh

推荐答案

对象必须是完全可序列化的,遗憾的是,使用只读集合时无法完成此操作,因为它们没有默认构造函数。但
这篇文章讨论了如何规避这一点(参见小标题"使用集合界面类型和只读集合""。

The objects has to be completely serializable, and unfortunately this cannot be done when using read-Only collections since they do not have a default constructor. But this article talks about how that maybe circumvented (see sub-title "Using Collection Interface Types and Read-Only Collections").

 

希望这有帮助,


这篇关于使用只读集合缓存对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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