2008-12-08 69 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

相關問題