multidimensional array - Passing C# List to X++ -
in c# project in microsoft dynamics ax 2012 aot have method returns list , wanted refer method in x++ code.
my initial thought should easy. like: list xppprojectlist = csharpgetprojectlist.getstringlist();
. however, didn't worked.
after extensive research on internet found out, use system.collections.arraylist
instead of list
, time works, single dimension collections.
x++ code that's supposed consume c# collection:
public void getprojectlist() { csharpgetprojectlist = new ps2010service.csharpgetprojectlist(); projectlist = csharpgetprojectlist.getstringlist(); length = projectlist.get_count(); (i = 0; < length; i++) { info(projectlist.get_item(i)); } }
c# method returning list<t>
works:
public static list<string> getstringlist() { list<string> list = new list<string>(); list.add("one"); list.add("two"); list.add("three"); return list; }
c# method returning arraylist
works:
public static arraylist getstringlist() { arraylist list = new arraylist(); list.add("one"); list.add("two"); list.add("three"); return list; }
c# method returning multidimensional arraylist
doesn't work:
public arraylist getstringlist() { arraylist list1 = new arraylist(); list1.add("one"); list1.add("two"); list1.add("three"); arraylist list2 = new arraylist(); list2.add("1"); list2.add("2"); list2.add("3"); arraylist list = new arraylist(); (int = 0; < list1.count; i++) { list.add(new string[] { list1[i].tostring(), list2[i].tostring() }); } return list; }
error returned is: clr interop marshal: unsupported type. error executing code: global (object), method info called invalid parameters. although can read length of arraylist
, returns 3.
same goes multidimensional list<t>
won't post here make question shorter.
so question - how consume c#'s multidimensional list in x++ code? thank you!
return value .net arraylist
string[2]
elements.
code should this:
system.collections.arraylist result = csharpgetprojectlist.getstringlist(); system.string[] netemement; str val1, val2; int i; (i=0; < result.get_count(); i++) { netemement = result.get_item(i); val1 = netemement.get_item(0); val2 = netemement.get_item(1); }
instead of for use enumerator:
system.collections.ienumerator netenumerator = result.getenumerator(); while (netenumerator.movenext()) { netemement = netenumerator.get_current(); val1 = netemement.get_item(0); val2 = netemement.get_item(1); }
Comments
Post a Comment