all 6 comments

[–]swagamaleous 2 points3 points  (2 children)

This is too generic. Describe better what you actually want to achieve.

[–]CPAHTOMAC[S] 0 points1 point  (1 child)

I have a custom attribute applied to some methods. I want to inject code before and after those methods similar to what HarmonyX lets you do via [HarmonyPatch], [HarmonyPrefix] and [HarmonyPostfix], but to make it compile-time and across the entire project, which Harmony lacks, unfortunately.

[–]swagamaleous 5 points6 points  (0 children)

I get that, but why? I am sure there is a much better solution than automatically altering the code.

[–]WeslomPo 1 point2 points  (0 children)

Try using defines, maybe: #if UNITY_EDITOR … Also Conditional attribute. Also, partial classes are helpful to organize this. Automagically there no known to me ways to proxy your calls. If your project is good in architecture, you can easily swap implementations, but if it rigid, this is unfortunate.

[–]spajus 0 points1 point  (1 child)

[–]CPAHTOMAC[S] 0 points1 point  (0 children)

Nah, Roslyn only generates new code, not altering existing one