我有这样的代码:
public abstract class Base
{
// is going to be used in deriving classes
// let's assume foo is threadsafe
protected static readonly Foo StaticFoo = new Foo();
}
Visual Studio 2008 的代码分析弹出此消息:
CA2104 : Microsoft.Security : Remove the read-only designation from 'Base.StaticFoo' or change the field to one that is an immutable reference type. If the reference type 'Foo' is, in fact, immutable, exclude this message.
我的设计是否存在内在缺陷,或者我可以[SuppressMessage]
在源代码中添加一个?