是的FxCop的CollectionPropertiesShouldBeReadOnly规则Spring框架不兼容? [英] Is FxCop's CollectionPropertiesShouldBeReadOnly rule incompatible with the spring framework?

查看:245
本文介绍了是的FxCop的CollectionPropertiesShouldBeReadOnly规则Spring框架不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的FxCop有 Col​​lectionPropertiesShouldBeReadOnly规则的抱怨,如果你的类有某种集合属性,客户端可以设置。相反,它意味着使属性只读和供给Clear()方法和添加()或的AddRange()方法用于改变集合的内容

FxCop has the CollectionPropertiesShouldBeReadOnly rule that complains if your class has some kind of collection property that clients can set. Instead, it suggests making the property read-only and supplying a Clear() method and Add() or AddRange() methods for changing the contents of the collection.

我同意,使一个更清洁,更易于控制的界面,但我努力使与Spring框架的接口工作。如果我要配置的对象与合作者的集合,我要揭露一些集合属性的合作者注入。我已经通过 Spring文档看,我可以'看不到任何的方式来告诉Spring调用的AddRange()方法中,我失去了一些东西?

I agree that makes for a cleaner and more controlled interface, but I'm struggling to make that interface work with the Spring framework. If I want to configure an object with a collection of collaborators, I have to expose some collection property to inject the collaborators into. I've looked through the Spring documentation, and I can't see any way to tell Spring to call the AddRange() method, am I missing something?

现在,我要排除警告有一张纸条,上面有必要的Spring配置。

For now, I'm going to exclude the warning with a note that it's necessary for Spring configuration.

更新:,因为我没有得到任何啃在这里的最后两个月,我贴在<一个同样的问题href="http://social.msdn.microsoft.com/Forums/en-US/vsts$c$c/thread/1f9c8929-01eb-4388-89e8-8462b61975f1"相对=nofollow>的FxCop论坛。

Update: since I didn't get any nibbles here in the last two months, I posted the same question on the FxCop forum.

推荐答案

如果集合属性只具有一个getter曝光,我们将承担的FxCop建议您列表的使用和添加到集合的模式。还支持第一种模式。

If the collection property only has a getter exposed, we will assume the FxCop recommended patterns you list is used and add to the collection. The first pattern is also supported.

有关泛型集合,这是唯一的工作,如果公开的属性是类型的IList的。我们有一个 JIRA问题的下一个版本中解决这个问题。顺便说一句,这是在基类库一个很常见的模式(你可能知道......),这是我们第一次遇到需要支持这种风格在.NET 1.1(不从上面列出的限制苦) 。

For generic collections this is only working if the exposed property is of the type IList. We have a JIRA issue for the next release to fix this. BTW, this is a very common pattern in the base class libraries (as you probably know...) which is where we first encountered the need to support this style in .NET 1.1 (which doesn't suffer from the limitation listed above).

干杯, 马克

这篇关于是的FxCop的CollectionPropertiesShouldBeReadOnly规则Spring框架不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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