handzlikchris / FastScriptReload

Hot Reload implementation for Unity. Iterate on code insanely fast without breaking play session. Supports any editor. 1. Play 2. Make change 3. See results
https://immersivevrtools.com/projects/fast-script-reload
MIT License
1.61k stars 115 forks source link

Try to fix rewrite for self file extension method [Workaround] #117

Open builder-main opened 10 months ago

builder-main commented 10 months ago

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 commented 10 months ago

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 commented 6 months ago

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 commented 6 months ago

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

builder-main commented 3 months ago

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 :(

There is the workaround in the meantime with classical static method syntax. Making a specific rewriter is a feasible task even for newcomers, you could look at the examples and try make a PR if this is a subject that is bothering you a lot.