我有什么
我想实现一个BackgroundWorker的同步替换,用于我的NUnit测试。根据我的研究,我目前有这个:
// Interface:
public interface IBackgroundWorker
{
// The properties, events and methods from BackgroundWorker go here
}
public delegate IBackgroundWorker BackgroundWorkerFactory();
// Implementation 1:
public class MyBackgroundWorker : BackgroundWorker, IBackgroundWorker
{
private MyBackgroundWorker() { }
public static MyBackgroundWorker Factory()
{ return new MyBackgroundWorker(); }
}
// Implementation 2 is a synchronous version
然而,FxCop却在抱怨这个宝石:
将方法MyBackgroundWorker.MyNamespace.IBackgroundWorker.set_WorkersSupportsCancellation(布尔)Void的参数名称"param0"更改为"value",以便与在IBackgroundWorker.set_WorkersupportsCancellance(布尔)Vaid中声明的标识符相匹配。
(它对RunWorkerAsync(object)
有类似的说明,因为这是接口上唯一一个采用参数的方法)
这个MSDN页面说我不应该抑制这个消息,但它说我应该抑制,因为这只是编译器生成的问题,FxCop的1.36版本修复了它
我想要什么
我想使用这个瘦包装器,而不需要将每个方法和属性代理到一个封闭的对象(这是可行的,可以避免这个问题,但作为一个经得起未来考验的设计来说并不理想)。
然后,我想抑制FxCop 1.35中的消息,最好在模块本身中使用SuppressMessage
属性,因为构建过程超出了我的控制范围(它是集中管理的)。
我尝试过的
我已经尝试了SuppressMessage的几种变体,基于我在网上其他地方发现的内容,比如这里,但都没有达到预期的效果。
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.MyBackgroundWorker.#set_WorkerSupportsCancellation(System.Boolean)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.MyBackgroundWorker.set_WorkerSupportsCancellation(System.Boolean)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.IBackgroundWorker.#set_WorkerSupportsCancellation(System.Boolean)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.IBackgroundWorker.set_WorkerSupportsCancellation(System.Boolean)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.MyBackgroundWorker.#set_WorkerSupportsCancellation(System.Boolean)System.Void")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.MyBackgroundWorker.set_WorkerSupportsCancellation(System.Boolean)System.Void")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.IBackgroundWorker.#set_WorkerSupportsCancellation(System.Boolean)System.Void")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1725", MessageId = "0#", Scope = "member",
Target = "MyNamespace.IBackgroundWorker.set_WorkerSupportsCancellation(System.Boolean)System.Void")]
如何在生成的代码中禁用特定的FxCop规则?有了答案-我可以使用Copy As->Module level SuppressMessage从GUI工具中获得完全限定的名称(我说得对,这是我无法正确获得的部分),它就起作用了。
在我的情况下,我需要指定
[module: SuppressMessage("Microsoft.Naming",
"CA1725",
MessageId = "0#",
Scope = "member",
Target = "MyNamespace.MyBackgroundWorker.MyNamespace.IBackgroundWorker.set_WorkerSupportsCancellation(System.Boolean):System.Void")]