
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
96 lines
2.0 KiB
Plaintext
96 lines
2.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When a base type explicitly implements a public interface method, that method is only accessible in derived types through a reference to the current instance (namely ``++this++``). If the derived type explicitly overrides that interface method, the base implementation becomes inaccessible.
|
|
|
|
|
|
This rule raises an issue when an unsealed, externally visible type provides an explicit method implementation of a ``++public interface++`` and does not provide an alternate, externally visible method with the same name.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
public interface IMyInterface
|
|
{
|
|
void MyMethod();
|
|
}
|
|
|
|
public class Foo : IMyInterface
|
|
{
|
|
void IMyInterface.MyMethod() // Noncompliant
|
|
{
|
|
MyMethod();
|
|
}
|
|
|
|
void MyMethod()
|
|
{
|
|
// Do something ...
|
|
}
|
|
}
|
|
|
|
public class Bar : Foo, IMyInterface
|
|
{
|
|
public void MyMethod()
|
|
{
|
|
// Can't access base.MyMethod()
|
|
// ((IMyInterface)this).MyMethod() would be a recursive call
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
public interface IMyInterface
|
|
{
|
|
void MyMethod();
|
|
}
|
|
|
|
public class Foo : IMyInterface
|
|
{
|
|
void IMyInterface.MyMethod()
|
|
{
|
|
MyMethod();
|
|
}
|
|
|
|
protected void MyMethod() // or public
|
|
{
|
|
// Do something ...
|
|
}
|
|
}
|
|
|
|
public class Bar : Foo, IMyInterface
|
|
{
|
|
public void MyMethod()
|
|
{
|
|
// Do something
|
|
base.MyMethod();
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Exceptions
|
|
|
|
This rule does not report a violation for an explicit implementation of ``++IDisposable.Dispose++`` when an externally visible ``++Close()++`` or ``++System.IDisposable.Dispose(Boolean)++`` method is provided.
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Make "XXX" sealed, change to a non explicit declaration or provide a new method exposing the functionality of "YYY".
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Explicit interface method implementation
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|