I have a class that uses a variety of methods and other classes as its members. In one of these methods, it does something like this:
MyObject.member1.doStuff();
MyObject.member2.doStuff();
MyObject.member3.doStuff();
MyObject.member4.doStuff();
等等。
I would like to do something like this instead:
foreach Member in MyObject
{
foreach Method in Member
{
if (Method.Name == "doStuff")
{ Method.Invoke() }
}
}
每个成员都属于不同类别,他们共同拥有的唯一东西是,他们都有一个称为“法律”的真空方法。 我不能把所有方法结合起来,采用一种巨大的教义方法。