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

发布于 2024-07-10 03:44:31 字数 2015 浏览 5 评论 0原文

当对具有尚未修改的单个窗口的 WPF 应用程序使用 FxCop 1.36 时,我收到 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)
}

是否应该忽略此问题?

When using FxCop 1.36 for a WPF application with a single window that has yet to be modified, I get the InterfaceMethodsShouldBeCallableByChildTypes error with the following details:

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

Should this simply be ignored?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你搞怪i 2024-07-17 03:44:31

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

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

Ignore it, this is standard code that is in every WPF application and you don't see people complaining about net being able to call IComponentConnector.Connect from derived classes - so it's probably safe.

In general I think you should handle FxCop output as suggestions that have to be considered carefully, I've got a lot of bad advice from FxCop in the past.

暗地喜欢 2024-07-17 03:44:31

取决于您期望继承人做什么。

如果您不希望此类被继承,那么应该将其密封,问题就会消失。

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

但是,这不是可继承类的预期行为,因此您应该公开公开接口(即隐式接口而不是显式接口)。

Depends on what you expect an inheriter to do.

If you are not expecting this class to be inherited then it should be sealed and the problem goes away.

If you are expecting it to be inherited then you are taking the ability of the inheriting class to override the interface methods and still call them (i.e. base.methodname()). If that is your intent then you can ignore the warning.

However, that is not expected behaviour for inheritable classes so you should expose the interface publicly (i.e. An implicit interface instead of an explicit interface).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文