[转]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 |
学习本是一个不断模仿、练习、创新的过程。对于自己,博文只是总结。在总结的过程发现问题,解决问题。对于他人,在此过程如果还能附带帮助他人,那就再好不过了。 感谢您的阅读。如果文章对您有用,那么请打赏我一杯咖啡,也可以轻轻点个推荐,以资鼓励。
微信打赏
支付宝打赏