Transferred from: http://blogs.msdn.com/b/emeadaxsupport/archive/2009/04/23/dynamics-ax-and-generic-collections-of-net.aspx
EmeadaxsupportAPR 9:54 AM
I ' m using Dynamics AX 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 is compiled as the class as The classes in the "System.Collections.Generic" namespace is not accepted.
Actually this type as well as every type defined in the namespace System.Collections.Generic is no regular types (is CLA sses) But they is so called "generics". You can see this for example if you were using a Generic in C #, where you had to specify the type of the Generic at Decl Aration/definition (Here for example for string):
System.collections.generic.list<string> List;
More information about. NET generics can is found here:
Generics (C # Programming Guide)
For Dynamics AX 4.0 generics is not supported by the X + + language. This was outlined in the Microsoft Press book "Inside Dynamics AX" on page 111:the following feature of the CLR cannot be used With X + +:
- Public fields (these can is accessed by using the 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 a own Assembly that's 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.collec tions. 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 |
The non-generic counterpart of "system.collection.generic.list<t>" would be "System.Collections.Arra Ylist ".
--author: |
Alexander Lachner |
--editor: |
Alexander Lachner |
--date: |
23/04/2009 |