2010-08-11 67 views
0

我有一個委託:Func鍵<>和Action <>無法找到

delegate ResultType Caller<ResultType>(IPtxLogic logic); 

這裏是一個函數:

private ResultType ExecuteLogicMethod2<ResultType>(string sessionId, 
    Caller<ResultType> action) 
    where ResultType : IResult, new() 
    {...} 

我希望像這樣的東西來替代函數簽名:

private ResultType ExecuteLogicMethod2<ResultType>(string sessionId, 
    Action<IPtxLogic, ResultType> action) 
    where ResultType : IResult, new() 
    {...} 

編譯器告訴我:

使用通用類型'System.Action'需要'1'類型參數

爲什麼?我怎樣才能訪問'標準'.NET類?

謝謝。任何想法都歡迎。

P.S.我創建我的自定義委託來解決問題,但是......我不想爲每個我的「自定義操作」的自定義委託...

delegate ResultType Action<ParameterType, ResultType>(ParameterType param); 

P.P.S.我使用.NET 3.5

回答

0

leppie,你最初的想法是正確的:

  1. 我需要添加 'System.Core程序' 組裝成的項目!
  2. 我需要使用Func鍵<> //但這不是問題

感謝的核心。

這些類型都包括到3.5外的開箱: http://msdn.microsoft.com/en-us/library/bb534960.aspx

版本信息 .NET框架 支持:4,3.5

4

請確保您引用 System.Core.dllusing System.Linq;

關於第二個想法。您正在使用Action代替Func。您需要Func<IPtxLogic, ResultType>

+1

'Action'和'Func鍵'在'System'命名空間中。然而,OP的錯誤消息表明他們已經'使用System',但是缺少對_System.Core.dll_的引用。 – 2010-08-11 17:40:14

+0

@Tim Robinson:不,不是這樣:) – leppie 2010-08-11 17:43:22

相關問題