pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.15k stars 485 forks source link

Way to override returned reference itself #582

Closed kohanis closed 6 months ago

kohanis commented 6 months ago

It is, on the whole, a suggestion. Currently, there is no way to override the reference itself in a method like ref T fn() This implementation adds an optional parameter out RefResult<T> __resultRef (out is a requirement as it is called immediately after the patch and nulled), where delegate ref T RefResult<T>() I don't have a user-case for this, but someone might have one

// On second thought, out requirement is unnecessary, ref is okay

kohanis commented 6 months ago

Lack of documentation is intentional until acceptance of feature itself is confirmed

kohanis commented 6 months ago

Added docs(Never been good at it, hope it's understandable), new test + initial reset + restructured. Lifted out requirement

pardeike commented 6 months ago

I will pull this and clean up any documentation if necessary later. Excellent work, much appreciated and great timing to get this into the next big release.

kohanis commented 6 months ago

Actually, I was wrong. This could have been achieved through prefix with skip and/or passthrough postfix. I completely forgot about them. But now it's too late to delete... Apologies

EDIT: Well, I suppose new method is a little more optimal