Discoverability of base class static methods

Feb 28, 2011 at 3:10 PM

I hope you can clear this confusion.


The situation is I have a base class in which I’ve implemented operator overloads for +, -, *, /, etc.  These, of course are static methods.  I have xml commented them all.


I have a derived class that does not re-implement these overloads.  Nevertheless, instances of this derived class obey the base class operator overloads quite happily.


I produce the help file documentation with Sandcastle Help File Builder.  As expected, the overloaded operators are listed as members of the base class.  However, the overloads are not included in the derived class member documentation.


I realise that this is because no static members from the base class are listed as derived class members.  However, a casual browser of the documentation might conclude that the derived class does not obey any operator overloads.


Of course, I can always include a link to the base class documentation from within the derived class documentation.  However, is there a better generally accepted way of improving the discoverability of these operator overloads?  Or, is there something I’m not understanding here?

Feb 28, 2011 at 11:18 PM

Static members are only listed in the base class, not derived classes.  This is true of the MSDN documenation for the base framework classes too and you'll see the same behavior in tools like Reflector.  This makes sense if you think about it as static members belong to the class in which they are declared and are not really inherited although operators are a special case and do act that way.  I don't know of any way to indicate the fact that the base class overloads the operators short of looking at it's member list to see if that's the case.



Mar 1, 2011 at 12:31 PM
Edited Mar 1, 2011 at 2:33 PM

Thanks for your answer, which is very helpful.  I perhaps did not tell the whole story.


I have made the operator overloads defined in my base class polymorphic.  That is, they call protected instance methods on one or other of their arguments.  Also, I have defined static “multi-language friendly” methods in the base class like Add, Subtract, Multiply, Divide, etc.  These methods apply the operator overloads and so also behave polymorphically.  So for example I can do the following.


BaseClass t1 = BaseClass.Multiply(baseInstance, baseInstance);                //t1 is baseInstance


BaseClass t2 = DerivedClass.Multiply(baseInstance, baseInstance);           //t2 is baseInstance


BaseClass t3 = BaseClass.Multiply(derivedInstance, derivedInstance);       //t3 is derivedInstance


BaseClass t4 = DerivedClass.Multiply(derivedInstance, derivedInstance);  //t4 is derivedInstance


It just seems a pity this functionality is not more apparent in the documentation but I do understand your explanation of why this is so.