开发者

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

开发者 https://www.devze.com 2023-02-07 14:36 出处:网络
I have a circumstance where I have enqueued a number of Action objects and I have a threadpool working through each Action. However, if the application shuts down before the queue is empty, I would li

I have a circumstance where I have enqueued a number of Action objects and I have a threadpool working through each Action. However, if the application shuts down before the queue is empty, I would like to log what is remaining in the queue before closing.

Is it possible to get the method body from an Action object? I can see the MethodBody object from Action.Method.GetMethodBody(), but 开发者_如何学PythonI don't see a way to get this out as a string.

Any thoughts, or am I crazy?

EDIT: One more thing; I would like to retain state information as well. That is, I would like to also retain the values of any variables used within the Action.


Yes, you're crazy.

The code being executed has been compiled down to IL, and then JIT compiled to machine code. The text of the action is long gone.

You need to not be queuing Action. Instead, create a structure which contains the Action and the method name, and any other information you want to have logged. Make a queue of those instead of Action.


I suppose you aren't looking for the textual representation, but for a way to load and save expression trees. I did encounter that problem as well, and while I didn't use it yet, this seems promising: expression tree serialization.

0

精彩评论

暂无评论...
验证码 换一张
取 消