確定這裏是另一種嘗試(現在仍然沒有明確的if語句!):
inFiles.ToList().ForEach(i =>
{
filePath = inFolder + "\\" + i.Value;
replacementCollection = testForReplacement(i,filePath,replacementFile);
standardizationCollection = testForStandardization(i,filePath,standardizationFile);
someOtherCollection_1 = testForOtherCollection(i,filePath,otherFile);
....//more statements like this...
});
...
...
...
Collection testForReplacement(i,filePath,testFile)
{
return i.Key.Equals(testFile) ? GetReplacementDataFromFile(filePath) :null;
}
Collection testForStandardization(i,filePath,testfile)
{
return i.Key.Equals(testFile) ? GetStandardizationDataFromFile(filePath) :null;
}
Collection testForSomeOtherCollection(i,filePath,testfile)
{
return i.Key.Equals(testFile) ? GetOtherDataFromFile(filePath) :null;
}
...///more functions like this...
這是更僞代碼比真正的代碼(不知道這將彙編原樣),但我希望它使重點。 ;)
該代碼看起來多餘,但很容易編寫一個腳本/宏,它可以獲取所有可能的文件類型的列表,並在模式更改時生成(或重新生成)所有必需的函數和語句使用它們。生成的代碼可以節省很多時間,如果你做得對!
爲什麼你覺得這有問題嗎? – Robin 2010-05-07 13:48:22
我不知道,@Robin,有一些奇怪的事情,至少有一件壞事。 – Will 2010-05-07 13:58:16
@Newbie這是一個問題目的代碼的縮短版本嗎?如果沒有,那麼我認爲這個代碼是好的 - 我從一個快速瀏覽中理解代碼,我認爲這是主要的。長如果陳述是一種潛在的「代碼異味」,並且你試圖改進,但如果陳述本身不是一個目標,那就太棒了。 – 2010-05-07 14:12:12