Skip to content

Conversation

@michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Jan 26, 2026

In this PR we introduce support for extension types (blocks). The feature is explained in detail here.
The feature generalises extensions to operators and properties.

Here is a small example of an declaration and how it can be invoked.

public static class MyExtensions
{
    extension(string s)
    {
        public bool IsValid() { return s is not null; }
    }
}

public class A
{
    public void M()
    {
        var s = "Hello World";
        s.IsValid(); // Call to extension method.
        MyExtensions.IsValid(s) // Call to compiler generated static method.
    }
}

It turns out that Roslyn generates a static method corresponding to the extension method. To avoid extracting multiple methods with identical bodies (which would further complicate the QL implementation) we

  • Only extract the IsValid() method, which has the qualified name MyExtensions.extension(string).IsValid.
  • Add a parameter s to IsValid() corresponding to the receiver parameter s. This needs to be synthesised as we can't re-use the parameter from the extension declaration.
  • Replace invocations of MyExtensions.IsValid with MyExtensions.extensions(string).IsValid.

@github-actions github-actions bot added the C# label Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant