Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Action delegate ignore parameter?

I have this:

public event Action<BaseCommodity> OnGatherActionSelected = delegate { };
gmp.OnGatherActionSelected += m_Worker.CharacterActions.StartGatherMaterials; // << takes a parameter

but now i want to use the event to call a method which takes 0 parameters

gmp.OnGatherActionSelected += ParentPanel.RedrawUI; // does not take parameters .. DOES NOT WORK :(

how can i do this?

like image 517
Cxyda Avatar asked Oct 11 '15 08:10

Cxyda


2 Answers

The easiest option is to add a handler that takes the parameter and ignores it, delegating to the method you want to use:

gmp.OnGatherActionSelected += _ => ParentPanel.RedrawUI();
like image 71
Charles Mager Avatar answered Oct 10 '22 20:10

Charles Mager


You can wrap it in a method that takes a parameter:

gmp.OnGatherActionSelected += x => ParentPanel.RedrawUI();
like image 37
Guffa Avatar answered Oct 10 '22 19:10

Guffa