here...
Does anyone know why I would be able to create an extension method for
Object in C# but not in VB? I understand why using ByRef for the first
parameter would work in VB but not C#, but this I just don't get at all...
J. Moreno <pl***@newsreaders.comwrote:
Hello,--
I'm trying to add an extension to Object using VB. It shows up in the
intellisense for other kinds of reference objects, but not if the
variable is simply declared as Object.
It works without problems when I use C#, but not from within VB...any
ideas as to what is going on?
Imports System.Runtime.CompilerServices
Module StringUtils
<System.Runtime.CompilerServices.Extension()_
Public Function eMyE(ByVal o As System.Object, _
ByVal sep As Char) As String
Return "1"
End Function
<System.Runtime.CompilerServices.Extension()_
Public Function eMyE(ByVal o As System.Object) As String
Return o.eMyE(" ")
End Function
End Module
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As _
System.EventArgs) Handles Button1.Click
Dim b As String ' sender.eMyE doesn't show up in intellisense
End Sub
End Class
## and here it is in C#
using System;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace TestExtensionsC
{
public static class StringUtils
{
public static string eMyE(this object str, char sep)
{
return "1";
}
public static string eMyE(this object str)
{ return str.eMyE(' '); }
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string b = sender.eMyE();
}
}
}
J. Moreno