Return a list to .NET Business Connector

丶灬走出姿态 提交于 2019-12-12 03:35:37

问题


Currently, I am using the following code:

        Axapta ax = new Axapta();
        string tableName;
        ArrayList ax_cont = null;
        ax.Logon(null, null, null, null);
        try
        {
            ax_cont = (ArrayList)ax.CallStaticClassMethod("Code_Generator", "tableNames");
            for (int i = 1; i <= ax_cont.Count; i++)
            {
                tableName = ax_cont[i].ToString();
                tablesCB.Items.Add(tableName);
            }    
        }
        catch { }

But I'm getting a type conversion exception.

What do I need to do in C# when a list is returned from ax dynamics as an AxpataObject?


回答1:


It depends on what Code_generator::tableNames() returns.

It certainly does not return an ArrayList but most likely an AX List, and the two are not the same and cannot be casted.

One way would be to let AX return a container, then access that.

Otherwise you could access the AX List directly using AxaptaObject

AxpataObject ax_cont = ax.CallStaticClassMethod("Code_Generator", "tableNames");
AxpataObject ax_it = ax_cont.Call("getEnumerator");
while (ax_it.Call("moveNext"))
     // Hope you get it


来源:https://stackoverflow.com/questions/14495638/return-a-list-to-net-business-connector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!