我目前正在開發一個MVC.NET 3應用程序;我最近參加了一個名爲「Bob叔叔」的Martin課程,這個課程激勵我(羞辱我)努力研究我目前的開發實踐,特別是我的重構習慣。我的控制器中的重構開關語句
所以:我的一些途徑符合:
{控制器}/{行動}/{類型}將被返回
凡類型通常確定的ActionResult的類型,例如:
public class ExportController
{
public ActionResult Generate(String type, String parameters)
{
switch (type)
{
case "csv":
//do something
case "html":
//do something else
case "json":
//do yet another thing
}
}
}
有沒有人成功地應用了「替換交換與polymorhism」重構到這樣的代碼?這是個好主意嗎?聽聽你使用這種重構的經驗會很棒。
在此先感謝!
嗨戴夫這看起來完全一樣,我正在尋找。感謝提供自定義模型綁定的提示,我認爲它在其他地方也會非常有用。 – iagomartinez
謹慎闡述?如果DataFormat.CSV是一個值,那麼你的方法是無效的C#。 – Kugel
ModelBinder將如何確定哪些重載是正確的? – Kugel