我应该忽略WPF InterfaceMethodsShouldBeCallableByChildTypes生成的代码?

StackOverflow https://stackoverflow.com/questions/351228

  •  20-08-2019
  •  | 
  •  

当使用的FxCop 1.36用于与还没有被修改的单个窗口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)
}

如果这简单地忽略?

有帮助吗?

解决方案

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

在一般我认为你应该处理的FxCop输出作为必须认真考虑的建议,我已经在过去得到了很多不错的建议,从FxCop的。

其他提示

取决于你所期望的inheriter做什么。

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

如果您希望它被继承,那么你正在服用的继承类的重写接口的方法,仍然称它们(即base.methodname())的能力。如果这是你的意图,那么你可以忽略此警告。

然而,这<强>不预期的可继承类行为,以便你应该公开揭露接口(即隐式接口而不是显式的接口)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top