我有大约 20 个具有几乎相同模式的函数,我在站点数组上运行,使用站点对象创建 SiteOperation 并执行一些操作(在这种情况下只有一个参数,但有时没有或更多)
int wantedBandwidthInLBps = 2048 / 8;
foreach (Sites site in _sitesManagement.GetAll())
{
SiteOperation siteOperation = new SiteOperation(site);
siteOperation.LimitBandwidth(wantedBandwidthInLBps);
}
foreach (Sites site in _sitesManagement.GetAll())
{
SiteOperation siteOperation = new SiteOperation(site);
siteOperation.KillJames();
}
foreach (Sites site in _sitesManagement.GetAll())
{
SiteOperation siteOperation = new SiteOperation(site);
siteOperation.FlyToMoon(2012, new TaskIdentifier(10,20));
}
是否可以包装此代码,所以我将只发送操作让我们说 _sitesManagement 它将在所有站点上运行此操作?