2011-12-06 55 views
0

有沒有一種方法可以在不輸入整個簽名的情況下編寫以下內容?委託聲明是否可以繼承另一個委託聲明?

//desired base signature 
    public delegate string BaseDelegate<TProfile, TResult>(string requestorID, DateTime sentDate, string serviceID, 
     string source, TProfile profile, out DateTime recieved, out DateTime sent, out string psatSystemID, out TResult[] result); 

//ugly version of child 
public delegate string CurriedDelegate<T>(string requestorId, DateTime sentDate, string serviceId, string source, 
T profile, out DateTime recieved, out DateTime sent, out string psatSystemID, out T[] result); 

//syntax sugar,doesn't compile 
    public BaseDelegate<T,T> CurriedDelegate<T>; //TProfile is same type as TResult 

回答

3

沒有,有沒有這樣做的方式,雖然你可以從BaseDelegate<TProfile, TResult>創建CurriedDelegate<T>如果兩個類型的參數都是一樣的。

在我看來,更好的解決方案是將各種參數封裝在一個單獨的類型中。開始時確實是一個可怕的長簽名,並且推測參數彼此相關。

(我也想盡量避免使用這麼多out參數 - ?也許你實際上得到類型來這裏封裝,一個用於輸入,一個輸出)

+0

耶的代碼我是在項目的這個階段調用超出範圍進行清理。從我所知道的情況來看,在大多數情況下,在該服務層的98%中甚至全部使用了2個參數。當你說我可以創建'CurriedDelegate '時,你的意思是實例化,而不是定義一個簡短/甜美的簽名,對嗎? > 80%的服務層代碼「TProfile」和「TResult」是相同的。 – Maslow

+0

@Maslow:是的,如果你已經有了'BaseDelegate ',你可以使用'新的CurriedDelegate (existingDelegate)'。 –