【发布时间】:2014-12-17 03:29:29
【问题描述】:
嘿,我想知道我是否可以将表达式转换为动作。 我需要使用表达式来获取 lambda 表达式的详细信息,同时我需要使用不同的方法执行它。我需要使用单个参数(动作或表达式)来获取表达式和实际操作: 顺便说一句,我需要这个来获取关于我做了什么样的断言的详细信息。 ex(Assert.true, Assert.False)
public void otherMethod()
{
SomeMethod(() => Assert.Equals("Dog","Cat"));
}
public void SomeMethod(Expression<Action> neededAction) //or public void SomeMethod(Action neededAction)
{
//i need to run the neededAction and get the details whether what assert i did and the inputs i used for the assertion
}
所以基本上我需要运行动作并且我需要获取它的方法信息。 谢谢~
【问题讨论】:
-
neededAction.Compile() -
这正是我所需要的。非常感谢^_^
标签: c# lambda expression action methodinfo