Intellisense Oddity?

Intellisense for overridden methods shows both the base and the overridden method in the derived object, even though you can't actually call the base method from the derived object. Bug or feebleminded developer? You be the judge:

Simple class which inherits from Object and overrides the ToString method:

using System;

namespace Test
{
class MainTest
{
[STAThread]
static void Main(string[] args)
{
OverriddenObject oo = new OverriddenObject();
Console.Write(oo.ToString());
Console.ReadLine();
}
}

class OverriddenObject : Object
{
public override string ToString()
{
return "Overridden" ;
}
}
}

Now for the (minimal) fun:

1. Mouse over oo.ToString() - or just trust me, the tooltip reads: “string OverriddenObject.ToString() (+1 overloads)”.
2. Odder still, if you backspace over and retype the open perinthesis that follows the ToString() to bring up the Intellisense, you'll see two methods. The signature for the second reads “string Object.ToString”. Now, this is no big deal, but to be really picky, this is wrong for two reasons - (a) it's not valid in this context. From where the cursor sits at “oo.ToString(”, it's impossible for me to call the “Object.ToString()” method. (b) It's a little misleading - let's say I decide that I want the Object.ToString() method, pick it from the dropdown, close the method call, and go about my business assuming I'm going to call the method Intellisense presented to me as one of my options. I've been mislead! Object.ToString() will never be called from oo.ToString(), since it's been overridden.

Now, this seems pretty nitpicky in this example context. It's a bigger deal when you think of the base and derived classes representing business objects like ExemptEmployee derived from Employee, InternationalOrder derived from Order, etc.

Is this (1) true and important (2) true and unimportant, or (3) untrue (as in I'm not understanding why Intellisense is showing what it does)?

1 Comment

Comments have been disabled for this content.