2
votes

I have C# class and method which returns the Dictionary. I can create the instance of this class in Axapta, call this method and return the collection to Axapta, but I can not iterate over this collection and get its keys and values.

Here is my Axapta code:

ClrObject  obj;
;
obj = document.findText("some"); // returns Dictionary<string, string>
length = obj.get_Count(); // returns 5 (fine!)
obj.MoveNext(); // doesn't works 

for (i = 0; i < length; i++ )
{
   obj.get_Key(i);  // doesn't work
}

Is the a way to iterate over Dictionary in Axapta ?

1

1 Answers

3
votes

There is neither a get_Key nor a MoveNext method on dictionaries.

MoveNext must be called on an enumerator. That said you can retrieve one by calling GetEnumerator on your dictionary and then use it:

System.Collections.Specialized.StringDictionary dotNetStringDict;
System.Collections.IEnumerator dotNetEnumerator;
System.Collections.DictionaryEntry dotNetDictEntry;
str tempValue;
;

dotNetStringDict = new System.Collections.Specialized.StringDictionary();
dotNetStringDict.Add("Key_1", "Value_1");
dotNetStringDict.Add("Key_2", "Value_2");
dotNetStringDict.Add("Key_3", "Value_3");

dotNetEnumerator = dotNetStringDict.GetEnumerator();
while (dotNetEnumerator.MoveNext())
{
    dotNetDictEntry = dotNetEnumerator.get_Current();
    tempValue = dotNetDictEntry.get_Value();
    info(tempValue);
}