.

Where did my .Net 3.5 generic extension go?

by Simon Deshaies 4. November 2009 16:34

There are those things in programming that if you just don't know. Well that you got to know. Where are your extension methods is one of those things.

Microsoft decided to put a bunch of extensions for string in System.Linq. Yeah, no big deal. Could you have guessed? Well it happens that if you don’t specify the namespace for a extension method you will not get any type of suggestion in intellisene as you get with regular methods. And that’s because the reflection will just never find it.

So this code would give you the error below if the “using System.Linq” was absent.

Code:

using System.Linq;

public class Class1
{
    void main()
    {
        string[] arr = new string[5];
        arr.Contains<string>("where is my extention");
    }
}

Error:

Error    1    'System.Array' does not contain a definition for 'Contains'
and no extension method 'Contains' accepting a first argument of type 'System.Array' could be found
(are you missing a using directive or an assembly reference?)    
c:\users\documents\visual studio 2010\Projects\ClassLibrary1\ClassLibrary1\Class1.cs    8    13    ClassLibrary1

This is not bad it’s just 1 men day down the drain.

Tags:

Comments

Powered by BlogEngine.NET
Theme by Mads Kristensen and Simon Deshaies

About the author

Simon Deshaies

Name of authorI do web development, I focus on your business processes by dramatically increasing your visibility. I develop strong Internet and Web applications. My main objective is to support your performance by optimizing your presence on the Web and to advise you on the best web technology to fit your needs.

Linked in profile

Specialties:
.NET development, Internet and Web applications.
HTML, XHTML, XML, XSL, CSS, ASP.NET, AJAX, C#, SQL.
Microsoft Windows Server 2000 to 2008, SQL Server 2000 to 2008, MySQL, IIS, DNS.

BlogRoll

Download OPML file OPML