C++/CLI使用Action <...,...>和Func <...>不受支持?

nie*_*ras 4 .net generics delegates c++-cli .net-3.5

它看起来不像C++/CLI中的System命名空间中对Action和Func委托的支持.至少不适用于多个通用参数,例如:

System::Action<int, int>^ action = nullptr;
System::Func<int, int>^ func = nullptr;
Run Code Online (Sandbox Code Playgroud)

两者都会导致错误,例如:

error C2977: 'System::Action' : too many generic arguments  
error C2955: 'System::Action' : use of class generic requires generic argument list 
Run Code Online (Sandbox Code Playgroud)

只有单个参数Action有效:

System::Action<int>^ action = nullptr;
Run Code Online (Sandbox Code Playgroud)

任何人,知道为什么或缺少什么来使这项工作.我正在使用Visual Studio 2008,该项目有目标框架3.5.

Bra*_*uff 8

以下是在mscorlib中定义的 -

Action
Action<T>
Run Code Online (Sandbox Code Playgroud)

但以下是在System.Core中定义的.

Action<T1, T2>
Func<T1, T2>
Run Code Online (Sandbox Code Playgroud)

您可能缺少对该程序集的引用.


Jar*_*Par 8

根据您使用的框架版本,ActionFunc类型的位置会有所不同.

在3.5框架中,Func(通用或非通用)的所有定义都驻留在System.Core.dll中.对于Action具有2个或更多通用参数的版本也是如此. Action并且Action<T1,T2>在mscorlib中.

在4.0框架中所有的定义FuncAction移动到mscorlib.System.Core中插入了类型转发器,现在指向mscorlib.

Silverlight 4.0更接近3.5框架解决方案.

确保您有适合您的解决方案的DLL的引用.