I have a method that expects an Action<string>
I call the method as follows:
commandProcessor.ProcessCommand(s=> ShowReceipt("MyStringValue"))
开发者_JAVA技巧
ProccessCommand(Action<string> action)
{
  action.Invoke(...); // How do I get the reffered string?
}
Do I have to use Expression<Action<string>> ? If so, how do I get the parameter values?
You would indeed have to use Expression<Action<string>>... and even then you'd have to make some assumptions or write quite a lot of code to make it very robust.
This post may help you - it's pretty similar - but I would try to think of an alternative design if possible. Expression trees are great, and very interesting... but I typically think of them as a bit of a last resort.
Usually you would call it like this:
 commandProcessor.ProcessCommand(s=> ShowReceipt(s)) 
or simply
 commandProcessor.ProcessCommand(ShowReceipt)
and supply the string to the action in the called method:
 ProcessCommand(Action<string> action) 
 { 
  action("MyStringValue"); 
 } 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论