2008-12-08 76 views
2

使用的FxCop 1.36 WPF应用程序与尚未被修改,我得到了以下详细信息InterfaceMethodsShouldBeCallableByChildTypes错误的单一窗口:我应该忽略WPF生成代码的InterfaceMethodsShouldBeCallableByChildTypes吗?

Target  : #System.Windows.Markup.IComponentConnector.Connect(System.Int32,System.Object) (IntrospectionTargetMember) 
    Resolution : "Make 'MainWindow' sealed (a breaking change if 
        this class has previously shipped), implement the method 
        non-explicitly, or implement a new method that exposes 
        the functionality of 'IComponentConnector.Connect(int, 
        object)' and is visible to derived classes." 
    Help   : http://msdn2.microsoft.com/library/ms182153(VS.90).aspx (String) 
    Category  : Microsoft.Design (String) 
    CheckId  : CA1033 (String) 
    RuleFile  : Design Rules (String) 
    Info   : "Explicit method implementations are defined with private 
        accessibility. Classes that derive from classes with 
        explicit method implementations and choose to re-declare 
        them on the class will not be able to call into the 
        base class implementation unless the base class has 
        provided an alternate method with appropriate accessibility. 
        When overriding a base class method that has been hidden 
        by explicit interface implementation, in order to call 
        into the base class implementation, a derived class 
        must cast the base pointer to the relevant interface. 
        When calling through this reference, however, the 
        derived class implementation will actually be invoked, 
        resulting in recursion and an eventual stack overflow." 
    Created  : 08/12/2008 22:26:37 (DateTime) 
    LastSeen  : 08/12/2008 22:41:05 (DateTime) 
    Status  : Active (MessageStatus) 
    Fix Category : NonBreaking (FixCategories) 
} 

如果这只是被忽略?

回答

0

忽略它,这是每个WPF应用程序中的标准代码,并且您没有看到有人抱怨网络能够从派生类调用IComponentConnector.Connect - 因此它可能是安全的。

一般来说,我认为你应该处理FxCop输出作为必须仔细考虑的建议,过去我有很多来自FxCop的不良建议。

+0

您是否发现有关此问题的任何官方参考? – BlackWasp 2008-12-09 19:34:27

0

取决于你期望继承者做什么。

如果你不希望这个类被继承,那么它应该被封闭,问题就会消失。

如果您期待它被继承,那么您将继承类的能力覆盖接口方法并仍然调用它们(即base.methodname())。如果这是你的意图,那么你可以忽略警告。

但是,这就是而不是预期的行为为可继承的类,所以你应该公开暴露接口(即一个隐式接口,而不是一个明确的接口)。

+0

我很高兴与一般规则。在这种情况下,这个问题涉及Visual Studio生成的代码,所以我想知道是否有以这种方式更改此代码的问题。 – BlackWasp 2008-12-09 19:33:44