您好,现在是 2024年11月26日 20点45分 星期二

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):

System.Collections.Generic.List<string> list;

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

[转]Dynamics AX and Generic collections of .Net,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。