【发布时间】:2015-02-13 19:26:20
【问题描述】:
我不确定这是否完全可能。但是我想做的是创建一个属性,当我调用 run 方法时,所有具有特定 run 属性的方法都会运行。我意识到这可以通过委托来完成,但我觉得如果它可以通过属性来实现,它可能看起来会更简洁一些。我应该注意到运行顺序并不重要。
基本设计:
//This is the method called that should start off the attribute chain
public void Run(){
//calling logic in here
}
[AutomatedRun]
private void Method1(){
}
[AutomatedRun]
private void Method2(){
}
【问题讨论】:
-
您需要使用反射...查找每个方法或属性的属性,然后通过调用属性的方法和方法本身来执行它。