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();
etc.
I would like to do something like this instead:
foreach Member in MyObject
{
foreach Method in Member
{
if (Method.Name == "doStuff")
{ Method.Invoke() }
}
}
Each member is of a different class type, the only thing they have in common is they will all have a void method called doStuff(). I cannot combine all methods into one giant doStuff() method.
Assuming the members you are talking about are properties, you can do the following very ugly code:
But as has been mentioned, it seems like a problem with your architecture.