Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment/document an override in C#?

Sometimes I override methods in base classes. Sometimes I even override them with an empty method, because what I want is to prevent the behavior.

In the past I would write something like this to show the intent of bypassing the base method:

protected override void OnMouseUp(MouseEventArgs e)
{
    // base.OnMouseUp(e);
}

(I know a commented line of code is a bad thing. I used to do it)

But I want to do better:

  • How do I document the intention of the override? specifically:
  • What do I write in the override's XML (<summary>?) documentation?
like image 453
Camilo Martin Avatar asked Oct 14 '25 08:10

Camilo Martin


1 Answers

For documentation, I would just use the built-in documentation tags:

/// <summary>Exiting drag mode on mouse up</summary>
protected override void OnMouseUp(MouseEventArgs e)
{
    ...

For clarifying the intention I would just put a comment like

protected override void OnMouseUp(MouseEventArgs e)
{
    // not calling the base implementation
    ...
}

The line

// base.OnMouseUp(e);

makes an impression that the call is commented out temporarily (and perhaps someone forgot to restore it back)

like image 178
Vlad Avatar answered Oct 16 '25 21:10

Vlad