This issue recently came up: How do you traverse the elements in an instance of an IEnumerable<T> from X++? The answer is not as simple as it should be. The problem is that the X++ language does not currently support generics as a firstclass part of the managed X++ story. This means that we need to do some tricks to make this work. At least it shows off the capabilities of the ClrObject class: It can take a string that designates the type that you want to create an instance of. The CLR runtime system is so cleverly designed that it allows decorating types so they designate generic types. This is done by appending the backtick character, followed by the number of generic arguments, enclosed by the argument types enclosed in angular brackets. So, the type System.Collections.Generic.List<int> is represented as System.Collections.Generoc.List`1[System.Int] With this knowledge the task is not hard: static void GenericTypeDemo(Args _args) { ClrObject o = new ClrObject("System.Collections.Generic.List`1[System.Int32]"); ClrObject enumerator; int theValue; // o is an instance of an IEnumerable<int> o.Add(1); o.Add(4); o.Add(12); print o.ToString(); enumerator = o.GetEnumerator(); while (enumerator.MoveNext()) { theValue = enumerator.get_Current(); print theValue; } pause; } |
Thursday, June 21, 2012
Traversing elements in an IEnumerable from X++
Subscribe to:
Post Comments (Atom)
How to identify the user that was used to change an object from AOT in AX2012
Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...
-
Combo boxes in Dialogs are added by adding a DialogField object with the type of an enum. The enum is then controlling what items you can pi...
-
This article explains: How to picking list through a job using X++ in Dynamics AX. Applied on: Dynamics AX 2009 SP1 Create a job a...
-
A while ago I had the need to translate labels, I was creating eMail bodys while using SysMailer and wanted to use different languages for d...
No comments:
Post a Comment