Is it possible to get the body of an action method (text)?

I have a circumstance when I selected several Action objects, and I have threadpool working through each Action . However, if the application closes before the queue is empty, I would like to register what remains in the queue before closing.

Is it possible to get the body of a method from an Action object? I see a MethodBody object from Action.Method.GetMethodBody() , but I see no way to get this as a string.

Any thoughts or am I crazy?

EDIT: One more thing; I would also like to keep information about the state. That is, I would also like to save the values โ€‹โ€‹of any variables used in Action .

+4
source share
2 answers

Yes, you are crazy.

The executable code was compiled to IL, and then the JIT was compiled to machine code. The text of the action is long gone.

You do not need to be in line. Instead, create a structure containing the name Action and the name of the method, as well as any other information that you want to register. Create a queue for them instead of Action.

+4
source

I assume that you are not looking for a textual representation, but for a way to load and save expression trees. I also ran into this problem, and while I haven't used it yet, this seems promising: serializing the expression tree .

+3
source

Source: https://habr.com/ru/post/1337555/


All Articles