Feeds:
Posts
Comments

Intellsense Bug

[Legacy Post from my Spanish blog]
Four days ago while I was working on LINQ I found an error of VS2008′s IntellSense. After notifying it at the Microsoft Connect site, I was ready to post a comment  about this issue. Before we see how to reproduce this error I have to say that I can see it because I read Jon Skeet’s C# book in the morning.

By definition, it is possible to have an extensor method of extensible type T and a static method in T that have the same signature. We should remember that an extension method is pure sintactic sugar, the this modifier makes the method get tagged with System.Runtime.CompilerServices.ExtensionAttribute if it complies with the other rules, thus, this is just a simple method.

It’s in this situation where IntellSense gets confused. Let’s reproduce it.

 public class A
 {
        public static void Method(A obj){Console.WriteLine("instance");}
        public static void Foo() { }
 }
 
 public static class AHelper
 {
        public static void Method(this A obj) { Console.WriteLine("extension");}
 }
 
 static class Program
 {
        static void Main()
        {
            A objA = new A();
            objA.Method();
            Console.Read();
        }
 }

At the second instruction of Main method, if you activate the IntellSense's engine after you type the punctuator (".")  you will see how the Method doesn't have the expected icon, and neither does the tooltip beginning with "(extension)":

Once finnish the writing the name we could see how its now recognized as an extensions method by IntellSense:

If we erase the static method of the class, the extension method is redeemed.

See you soon bloggers :)

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Follow

Get every new post delivered to your Inbox.