Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c#] methodFullName for extension method calls #5245

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

xavierpinho
Copy link
Contributor

Extension methods are syntactic sugar that underneath expand to the resolved method call, e.g.

x = new MyClass();
x.DoStuff(); // is actually rewritten by Roslyn as MyClassExtensions.DoStuff(x);

class MyClass {}
static class MyClassExtensions {
  public static void DoStuff(this MyClass c) {}
}

See: Binding Extension Methods at Compile Time

This PR is only a first move towards "full support" (as much as it's feasible) and fixes the methodFullName properties of those calls. So, in x.DoStuff(), it's still a dynamic dispatch call with an argument x, but whose fullName is no longer MyClass.DoStuff():<unresolvedSignature> but rather MyClassExtensions.DoStuff:void(MyClass). I'd like to refactor astForInvocationExpression a little bit more before piling more stuff into it, as it's quite large as it stands already.

@xavierpinho xavierpinho added the c# Relates to csharpsrc2cpg label Jan 22, 2025
@xavierpinho xavierpinho merged commit 723a8e7 into master Jan 23, 2025
5 checks passed
@xavierpinho xavierpinho deleted the xavierp/c#-start-extension-methods branch January 23, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c# Relates to csharpsrc2cpg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants