Tags: vb.net |
Posted by
Admin on
5/17/2008 4:08 AM |
Comments (0)
[UPDATE]
Solved... well, not solved, but explained. The VB team has valid reasons for not supporting object as an extension parameter type. The key to take away from the linked article is that, when you specify object, it means "take anything *other* than an object".
http://blogs.msdn.com/vbteam/archive/2007/01/24/extension-methods-and-late-binding-extension-methods-part-4.aspx
[/UPDATE]
I'm trying to create an extension method that takes any object. It's irrelevant what I want it to do. The problem is that I can't get Extension Methods that take objects to work correctly in VB.NET. I don't have any problems with doing this in C#.
I created a simple console app to show my issues. I have two extension methods. One takes an object, and one takes a string. The code, along with the issues I'm having, are shown in detail below.
With a string, both methods show up in Intellisense.

With an object, the object extension method doesn't appear

However, it will compile

When running, however, an error occurs on the o.TestObjExt() line

Oh, but wait, if I run the same line from the Immediate window, it works!

So, I don't know what's happening. It seems to be a compiler issue, but I can't figure it out. Does anybody have any ideas what might be going on?
019d0e86-62b4-4fb3-ba56-54dce8a262e2|0|.0