Return a list to .NET Business Connector

2019-09-07 15:16发布

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条回答
【Aperson】
2楼-- · 2019-09-07 15:53

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
查看更多
登录 后发表回答