我在一個框架,有以下方法簽名工作如何消除歧義的重載方法
public ImageLinkButton AddToolBarButton(string commandName, string text, string toolTip, string imageUrl, string confirmMessage, bool defineID = false)
我發現我需要一個額外的布爾參數重載這個
public ImageLinkButton AddToolBarButton(string commandName, string text, string toolTip, string imageUrl, string confirmMessage, bool causesValidation, bool defineID = false)
然而,在使用中我看不出如何確保實際調用哪種方法,因爲調用
MyWhatsit.AddToolBarButton("cmdname", "text", "toolTip", "URL", "confirm", true);
可能調用要麼(假設我的頭腦直着)。
我很確定我做錯了什麼,但我什麼都看不到!
感謝
愛德華
我喜歡下面的命名參數的想法。你也可以重命名方法? – Mzn 2013-05-09 10:51:28
..或者爲CausesValidation指定一個默認值,並在沒有它的情況下刪除超載... – m0sa 2013-05-09 10:52:27