我正在尝试重构所有开关之母,但我不确定该怎么做。这是现有的代码:
private void SetPrepareFiles(
ObservableCollection<PrepareElement> prepareElements)
{
DateTime fileLoadDate = DateTime.Now;
string availabilityRequestFile = string.Empty;
string infrastructureFile = string.Empty;
string gsQualityFile = string.Empty;
string pvdnpProducedFile = string.Empty;
string docFile = string.Empty;
string actualCurrentStateFile = string.Empty;
string actualIpPlanFile = string.Empty;
foreach (var prepareElement in prepareElements)
{
switch (prepareElement.MappingName)
{
case "AvailabilityRequest":
availabilityRequestFile = prepareElement.FileName;
break;
case "SystemInformation":
docFile = prepareElement.FileName;
break;
case "ITStatus":
infrastructureFile = prepareElement.FileName;
break;
case "ActualIPPlan":
actualIpPlanFile = prepareElement.FileName;
break;
case "ActualCurrentState":
actualCurrentStateFile = prepareElement.FileName;
break;
case "Produced":
pvdnpProducedFile = prepareElement.FileName;
break;
case "Quality":
QualityFile = prepareElement.FileName;
break;
}
}
var fc = new FilesConverter.FilesConverter();
fc.SetCommonFiles(availabilityRequestFile, actualCurrentStateFile,
actualIpPlanFile, fileLoadDate);
}
我将如何重构这个 Switch to a Dictionary