[转]Dynamics AX and Generic collections of .Net
转自:http://blogs.msdn.com/b/emeadaxsupport/archive/2009/04/23/dynamics-ax-and-generic-collections-of-net.aspx
I'm using Dynamics AX 2009 and want to instantiate the .NET class "System.Collections.Generic.List" in X++.
Intellisense expands the class to "System.Collections.Generic.List`1" however the code cannot be compiled as the class as well as all other classes in the "System.Collections.Generic" namespace are not accepted.
Actually this type as well as every type defined in the namespace System.Collections.Generic are no regular types (are classes) but they are so called "Generics". You can see this for example when you are using a Generic in C#, where you have to specify the type of the Generic at declaration / definition (here the for example for string):
More information about .NET Generics can be found here:
Generics (C# Programming Guide)
For Dynamics AX 4.0 Generics are not supported by the X++ language. This is outlined in the Microsoft Press book "Inside Dynamics AX" on page 111: The following feature of CLR cannot be used with X++:
- Public fields (These can be accessed by using CLR reflection classes.)
- Events and delegates
- The ref parameter modifier
- The out parameter modifier
- Generics
- Inner classes
- The Container composite type
- The Array composite type
- Namespace declarations
Besides the "swapping" of the Generic collection into an own Assembly that is referenced back in to Dynamics AX, the only recommendation is to use the Non-Generic counterpart of the collection (see table below).
Generic | Non-Generic | |
---|---|---|
System.Collections.Generic | System.Collections | |
Collection<T> | CollectionBase | |
Comparer<T> | Comparer | |
Dictionary<K, V> | Hashtable | |
List<T> | ArrayList | |
Queue<T> | Queue | |
SortedDictionary<K, V> | SortedList | |
Stack<T> | Stack | |
ReadOnlyCollection<T> | ReadOnlyCollectionBase |
So in our case the Non-Generic counterpart of "System.Collection.Generic.List<T>" would be "System.Collections.ArrayList".
--author: | Alexander Lachner |
--editor: | Alexander Lachner |
--date: | 23/04/2009 |
学习本是一个不断模仿、练习、创新的过程。对于自己,博文只是总结。在总结的过程发现问题,解决问题。对于他人,在此过程如果还能附带帮助他人,那就再好不过了。 感谢您的阅读。如果文章对您有用,那么请打赏我一杯咖啡,也可以轻轻点个推荐,以资鼓励。

微信打赏

支付宝打赏
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?