代码之家  ›  专栏  ›  技术社区  ›  Budda

找不到Func<>和Action<>

  •  0
  • Budda  · 技术社区  · 15 年前

    我有一位代表:

        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'型别引数

    为什么?如何访问“standard”.NET类?

    非常感谢。任何想法都是受欢迎的。

    另外,我已经创建了自定义代理来解决问题,但是。。。我不想为我的每个“自定义操作”创建自定义委托。。。

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

    2 回复  |  直到 15 年前
        1
  •  4
  •   leppie    15 年前

    确保你引用 System.Core.dll using System.Linq;

    仔细想想。您正在使用 Action 代替 Func .

    你需要 Func<IPtxLogic, ResultType>

        2
  •  0
  •   Budda    15 年前

    莱皮,你最初的想法是对的:

    1. 我需要补充一下System.Core'装配到项目中!

    谢谢。

    这些类型包括在3.5开箱即用中: http://msdn.microsoft.com/en-us/library/bb534960.aspx

    版本信息 .NET框架