How to implement method command (C#)?

There is a Buff class with the methods Enable() Update() Setup() ReEnable() Abort().
Is the Action class that contains the List buffs.

How to implement the method from the Action like this: Action.BuffsOperation( Update ), which for each buff from this list by an appropriate method, Update() etc?

Know about Command pattern but may be, for such there is something easier, for example with delegates?
June 14th 19 at 20:09
1 answer
June 14th 19 at 20:11
Make a enum with arguments to BuffsOperation in BuffsOperation switch and sort the sheet by calling the corresponding method does not suit you?
Now it is done, but maybe there is a more elegant solution, without duplicating code. - Seth68 commented on June 14th 19 at 20:14
And where is the duplication
void BuffsOperation(myEnum en){
 foreach (Buff buff in buffs)
 case Update: buff.update();break;
 case Enable: buff.enable();break;
- Alene56 commented on June 14th 19 at 20:17
You can still in the Action class make the methods, Update,Abort...which will vyzyvaetsya
the same methods of a class Buff, summon buffs.ForEach(Update); well, it will look worse, leave it as is, and still do - Alene56 commented on June 14th 19 at 20:20
Yes, in your case there is no duplication, but there is a constant switch for each element. Maybe I
"extreme savings" - the game can be a lot of action in the second. Although it is likely that delegates will performance the same as a permanent switch. (Edit) But I don't know how to implement other methods (via delegates) in order to compare the performance. - Seth68 commented on June 14th 19 at 20:23

Find more questions by tags C#