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

Try to fix rewrite for self file extension method #117

Open
builder-main opened this issue Jan 17, 2024 · 3 comments
Open

Try to fix rewrite for self file extension method #117

builder-main opened this issue Jan 17, 2024 · 3 comments

Comments

@builder-main
Copy link

Hi, let's try to make a rewriter for extension methods. It would allow to avoid ambiguous call compilation errors :

public static class SomeClass {

  public static void MyExtension(this string myString){  ... }

  public static void MyMethod(){  "someValue".MyExtension() } //Will cause an ambiguous call in the compiler

  public static void MyMethod(){  MyExtension("someValue") } //This works and is the current workaround.
}
@handzlikchris
Copy link
Owner

Thanks - I think extensions are also part of other feature. Off top of my head there were some more issues with that unfortunately.

I think especially for rewritten code where YourType would end up YourType__Patched_ and extension method will complain.

We could probably cast it to (ProperType)(dynamic)variable. That's a hack for compiler as your variable is still of old type, same approach is used for something else already (I think for 'this' rewritting)

@BillDong2021
Copy link

BillDong2021 commented May 15, 2024

Is it not possible for rewriting extension methods yet now? Currently I’m working with one ECS framework of Unity, and it uses extension method almost everywhere :(

@handzlikchris
Copy link
Owner

sorry, I've not had a chance to get to it. I could point you in the right direction if you want to give that a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants