views:

92

answers:

2

Looking at the Project Server 2010 SDK (found here in .NET Reflector, I have found something interesting that confuses me.

Apparently, the SvcProject.ProjectClient class in ProjectServerServices.dll inherits from System.ServiceModel.ClientBase<Project>, which is an abstract class that implements the System.IDisposable interface. However, when I inspect the SvcProject.ProjectClient class (which is not abstract), there is no Dispose method. What gives? I thought that every method inherited from interfaces had to be implemented in a concrete implementation (otherwise what's the use of interfaces). Is .NET Reflector lying to me? Did Microsoft for some reason circumvent this requirement? What's going on?

+9  A: 

It's probably been implemented explicitly, like this:

void IDisposable.Dispose()
{
    // Code here
}

Either that or it inherits the method from the base class. Just because ClientBase<T> is abstract doesn't mean that it can't have implemented IDisposable properly itself. Indeed, it will have to either implemented it or redeclared it as an abstract method to force the derived class to implement it.

Either way, the method will be there somehow.

Explicit interface implementation means that the method is only available when the instance is viewed via the interface type. For example:

class Foo : IDisposable
{
    void IDisposable.Dispose() {}
}

...

Foo foo = new Foo();
foo.Dispose(); // Invalid: compile time error
IDisposable d = foo;
d.Dispose();   // Valid
((IDisposable)foo).Dispose(); // Valid (no need for temp variable)
Jon Skeet
Yeah, it was implemented explicitly in the base class. I missed it because of it being `IDisposable.Dispose` instead of just `Dispose`.
Steven Oxley
+6  A: 

Without looking, I would say that the base class provides the Dispose method and the concrete class simply doesn't override it. EDIT: And (after looking), it does provide a non-abstract, explicit implementation as IDisposable.Dispose.

tvanfosson
Hmm, I'm not seeing an implementation in the concrete class (`SvcProject.ProjectClient`), but you were right about the base class providing an implementation. I'm kind of new to C# and am not used to having to cast to an interface in order for the compiler to recognize that a class implements an interface.
Steven Oxley