Devo ignorare InterfaceMethodsShouldBeCallableByChildTypes per il codice generato da WPF?

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

  •  20-08-2019
  •  | 
  •  

Domanda

Quando utilizzo FxCop 1.36 per un'applicazione WPF con una singola finestra che deve ancora essere modificata, ottengo l'errore InterfaceMethodsShouldBeCallableByChildTypes con i seguenti dettagli:

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

Questo dovrebbe semplicemente essere ignorato?

È stato utile?

Soluzione

Ignoralo, questo è il codice standard presente in ogni applicazione WPF e non vedi persone che si lamentano del fatto che net sia in grado di chiamare IComponentConnector.Connettiti dalle classi derivate, quindi è probabilmente sicuro.

In generale penso che dovresti gestire l'output di FxCop come suggerimenti che devono essere considerati attentamente, in passato ho ricevuto molti cattivi consigli da FxCop.

Altri suggerimenti

Dipende da cosa ti aspetti che faccia un erede.

Se non ti aspetti che questa classe venga ereditata, allora dovrebbe essere sigillata e il problema scompare.

Se ti aspetti che sia ereditato, stai sfruttando la capacità della classe ereditaria di sovrascrivere i metodi dell'interfaccia e comunque di chiamarli (cioè base.methodname()). Se questo è il tuo intento, puoi ignorare l'avvertimento.

Tuttavia, questo è non comportamento previsto per le classi ereditabili, quindi è necessario esporre l'interfaccia pubblicamente (ovvero un'interfaccia implicita anziché un'interfaccia esplicita).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top