In C# is it possible to have a method accepting a delegate that has zero, 1 or many parameters?
In the method below i want to be able to do al kind of things when i click yes on the dialog box. I used a delegate for this but currently it only accepts methods without parameters.
There are probably multiple ways to do this like passing a generic class containing the parameters but what is the best way to do this? Does C# provide something out of the box to do this in a elegant way?
public static bool ShowCustomDialog(string message,
string caption,
MessageBoxButtons buttons,
XafApplication application,
Action onYes = null)
{
Messaging messageBox = new Messaging(application);
var dialogResult = messageBox.GetUserChoice(message, caption, buttons);
switch (dialogResult)
{
case DialogResult.Yes:
onYes?.Invoke();
break;
}
return false;
}
Action<T>,ActionT1, T2, ...>.