Giter Club home page Giter Club logo

Comments (7)

pardeike avatar pardeike commented on May 12, 2024 1

Latest master has support for MethodBase __originalMethod

from harmony.

rumkex avatar rumkex commented on May 12, 2024

Might be even better to allow passing some sort of arbitrary context object to provide a global state between calls to detour methods (like __state parameter allows preserving context inside a single method call, that new global state object will persist between calls and will be created together with the patch), what do you think?

from harmony.

Trojaner avatar Trojaner commented on May 12, 2024

I'm trying to do some profiler which starts a Stopwatch on the prefix and stops given Stopwatch on the postfix, to log its result and the method name. The prefix and postfix only have __instance and __state (__state = StopWatch) parameters and can be used for any method. But currently I can not use the same Prefix/Postfix for all methods, because I can not get the current patched methods name (except maybe some "hacky" way using StackTrace, which returns MethodName_PatchX; then using Regex to remove the _PatchX part. But this does not work for methods with overloads).

I'm not sure if that is possible using the context you described.

from harmony.

pardeike avatar pardeike commented on May 12, 2024

This conflicts with multiple assemblies patching the same method. Harmony must work across assembly boundaries and in order to have cumulative patches it serializes and deserializes patches to rebuild the final replacement method from all existing patches every time someone adds a new patch to the original.

So holding state for one particular original method consistently seems kind of hard and would require serialization of the data structures. It might even be that someone patches after you and thus your patch becomes part of their assembly and cannot handle its own types anymore since TypeA is not assignable from TypeA if they are from different assemblies.

My best guess would be to have the unchanging MethodBase from the original method as an injection parameter and you would need to have your own way to look up that in your own state. It could be called “MethodBase __original”.

from harmony.

Trojaner avatar Trojaner commented on May 12, 2024

I have already tried to add such a parameter, but it seems like its a bit tricky

from harmony.

pardeike avatar pardeike commented on May 12, 2024

A simple option would be to use the already provided Transpiler patch function. It can have the original method parameter as a parameter. It also has the advantage that you will get less overhead because you can implement your measurements without subroutine calls and that might save you some execution time too (depending on how time critical your patched methods are).

from harmony.

Trojaner avatar Trojaner commented on May 12, 2024

Thank you!

from harmony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.