正如您在我的代码中看到的那样,我想将一个方法保存(设置)到一个对象中。并使用该对象调用该方法...
请看代码,您可以轻松理解;用简单的英语很难解释...
我的问题是;当然“动作操作”对象不能保存将被调用的方法。
那么,我该如何解决这个问题呢?我能做些什么?
...
enum CampaignUserChoice
{
Insert,
Update,
Delete,
Disable
}
private void AskUserAboutCampaignOperation(CampaignUserChoice choice)
{
string questionForUser = string.Empty;
string questionTitleForUser = string.Empty;
Action operation; //<<<<--------------------- this line, it's method holder
if (choice == CampaignUserChoice.Insert)
{
questionForUser = "Do you want to create a new campaign?";
questionTitleForUser = "NEW CAMPAIGN";
operation = InsertCampaign(TakeDatasFromGui()); //<---------- set which method you want to call
}
else
{
operation = UpdateCampaign( campaignId, TakeDatasFromGui());
}
//TODO write other elses...
switch (MessageBox.Show(questionForUser, questionTitleForUser, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
{
case DialogResult.Yes:
operation; //<<<------------------ call method here...
break;
case DialogResult.No:
// "No" processing
break;
case DialogResult.Cancel:
// "Cancel" processing
break;
}
}
非常感谢大家的回答...