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

Add a way to access the returned value of the original method #53

Open
ascott18 opened this issue May 3, 2023 · 1 comment
Open

Add a way to access the returned value of the original method #53

ascott18 opened this issue May 3, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@ascott18
Copy link
Contributor

ascott18 commented May 3, 2023

I need a way to receive the original return value of the underlying method, and then either keep that return value, mutate it, or replace it entirely with a different value.

Something to the effect of this:.

MethodInfo myMethod;
var plug = Nasal.InstanceMethod<MyReturn>(myMethod)
    .ReturnWrapped((object instance, MyReturn originalReturn, MyParam p1, MyParam p2) =>
    {
        // Do stuff, and either return `originalReturn` or some other value

        return ...
    });
@Keboo
Copy link
Owner

Keboo commented May 3, 2023

I dug into this a bit more (documenting here so I don't forget).

The reason this is not possible with the current API is because when using a plug, it only registers a prefix (BaseMethodHandler.Patch). To be able to what is described above would mean one of two things:

  1. Implicitly set the CallOriginal flag so that the original plugged method still gets called. We would the need to invoke the user provided delegate and replace the return value with the user provided value.
  2. What is being described is the Postfix behavior. We could provide an API for getting access to this. This is probably the better solution.

@Keboo Keboo added the enhancement New feature or request label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants