This rule is Obsolete | |
Synopsis: | Use explicit interface implementation only to prevent name-clashing or to support optional interfaces |
Language: | C# |
Severity Level: | 5 |
Category: | Object oriented |
Description: |
When you use explicit interface implementation, then the methods implemented by the class involved will not be visible through the class interface. To access those methods, you must first cast the class object to the requested interface. It is recommended to use explicit interface implementation only:
Consider the following example.
public interface IFoo1 { void Foo() } public interface IFoo2 { void Foo() } public class FooClass : IFoo1, IFoo2 { // This Foo is only accessible by explictly casting to IFoo1 void IFoo1.Foo() { ... } // This Foo is only accessible by explictly casting to IFoo2 void IFoo2.Foo() { ... ) } |