views:

47

answers:

1

I want to explicitly implement an interface method on a base class.

Beyond this, I wanted to make this method virtual so I could override it on a derived class, but explicitly implemented methods do not allow this.

I have tried making a protected virtual method in the base, calling this from the interface method, and then overriding this method in the derived class. This seems to work but FxCop is complaining with rule CA1033 "Interface methods should be callable by child types".

(My base class implements the interface, the derived class does not.)

How should I improve this (abbreviated) code to be more correct, or should I just ignore FxCop in this case?

In the base class:

protected virtual string ConstructSignal()
{
    return "Base string";
}

#region ISignal Members

string ISignal.GetMessage()
{
    this.ConstructSignal();
}

#endregion

In the derived class:

protected override string ConstructSignal()
{
    return "Derived string";
}
A: 

Decided to implement the interface methods implicitly in the end, which still works and keeps FxCop happy.

Andy