代码之家  ›  专栏  ›  技术社区  ›  BlackWasp

对于WPF生成的代码,我是否应该忽略InterfaceMethodsShouldbycallableByChildTypes?

  •  2
  • BlackWasp  · 技术社区  · 17 年前

    当将FxCop 1.36用于带有一个尚未修改的窗口的WPF应用程序时,我得到InterfaceMethodsShouldbycallableByChildTypes错误,详细信息如下:

        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)
    }
    

    这应该被忽略吗?

    2 回复  |  直到 17 年前
        1
  •  0
  •   Nir    17 年前

    忽略它,这是每个WPF应用程序中的标准代码,您不会看到有人抱怨net能够调用IComponentConnector.Connect从派生类进行连接,所以这可能是安全的。

    一般来说,我认为您应该将FxCop输出作为建议来处理,这些建议必须仔细考虑,过去我从FxCop那里得到了很多不好的建议。

        2
  •  0
  •   Brody    17 年前

    取决于您希望继承者做什么。

    如果您不希望继承这个类,那么应该将它密封起来,问题就会消失。

    base.methodname() ).如果这是你的意图,那么你可以忽略警告。

    但是,就是 不