roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Allow VB to consume extension properties

Open chucker opened this issue 7 months ago • 3 comments

Is your feature request related to a problem? Please describe.

I would like to use C# 14's extension properties, e.g.

var s = "";
Console.WriteLine(s.IsFancy);

public static class StringExtensions
{
    extension(string s)
    {
        public bool IsFancy => true;
    }
}

…but then also to consume them in VB.

However, while VB does see extension methods even when they're in the new extension container syntax, it doesn't appear to see extension properties.

Describe the solution you'd like

It would be great if extension properties simply showed up in IntelliSense.

It would also be workable if VB merely saw methods, i.e. string.get_IsFancy in the above case, although the syntax wouldn't be quite as nice for a setter.

Additional context

For now, I'll manually write method wrappers so the extension properties can sort of be accessed from VB.

chucker avatar Jun 05 '25 09:06 chucker

From VB, you are able to consume as StringExtensions.get_IsFancy(s), right?

RikkiGibson avatar Jun 10 '25 19:06 RikkiGibson

Yep. However, that does mean I lose:

  • extension semantics (StringExtensions.get_IsFancy(s) rather than s.get_IsFancy())[^1], as well as
  • property semantics (mostly relevant in a setter: set_isFancy(newValue) instead of IsFancy = newValue)

[^1]: This also means that, when browsing through IntelliSense for a string, the existence of the extension isn't surfaced. In VS, if there are extension methods for a type, those are offered, even if the namespace hasn't been imported yet.

chucker avatar Jun 11 '25 08:06 chucker

+1

skurth avatar Dec 02 '25 13:12 skurth