How to get the instance of a referred instance from a lambda expression

前端 未结 2 888
情话喂你
情话喂你 2020-12-16 01:09

I have this lambda expression Expression> commandToExecute

Then I pass an instance of a class in there with a method:

         


        
2条回答
  •  孤街浪徒
    2020-12-16 01:35

    It is not possible "out of the box", you may be able to hack something with reflection, but that is not advisable, it will be very backwards.
    Edit: Actually possible according to Ronald, but still quite backwards. Hidden side effects like this make the code hard to read and maintain.

    Instead your ProcessCommand should take either the whole aClass object or more preferably an IMyCommand interface with .Method() and the additional methods and properties that ProcessCommand needs. Then the aClass.GetType() type should implement IMyCommand.

提交回复
热议问题