I would like to have a compiler warning when a class overrides one method but does not override a related function. How do you do this?
For example, if you override Object.Equals you get a warning if you do not override Object.GetHashCode().
I would like to have a compiler warning when a class overrides one method but does not override a related function. How do you do this?
For example, if you override Object.Equals you get a warning if you do not override Object.GetHashCode().
You can't, basically. That is a special case to prevent chaos.
The best you could do is write an FxCop rule to detect it.
You can't create your own compiler warning, but you can create a runtime warning, for example (if the overrides don't call the base method) having a flag that is set by the first base method that is then checked by the second base method. Or you could do more complicated things with reflection & stack traces to check for correct usage at runtime.
I think you could do it with some attributes and some reflection, but it gets messy very quickly.