هل يجب أن أتجاهل InterfaceMethodsShouldBeCallableByChildTypes للتعليمات البرمجية التي تم إنشاؤها بواسطة WPF؟

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 في الماضي.

نصائح أخرى

يعتمد على ما تتوقع أن يفعله الوريث.

إذا كنت لا تتوقع أن يتم توريث هذه الفئة، فيجب إغلاقها وتختفي المشكلة.

إذا كنت تتوقع أن يتم توريثها، فأنت تستفيد من قدرة الفئة الموروثة على تجاوز طرق الواجهة وما زالت تستدعيها (على سبيل المثال. base.methodname()).إذا كانت هذه هي نيتك، فيمكنك تجاهل التحذير.

ومع ذلك، هذا هو لا السلوك المتوقع للفئات القابلة للتوريث لذا يجب عليك الكشف عن الواجهة علنًا (على سبيل المثال.واجهة ضمنية بدلاً من واجهة صريحة).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top