Dynamics AX 2009 AOT Digger
Generate type safe c# code for:
  • AOT
    • Tables
    • Base Enums
    • Classes
  • kernel
    • Tables
    • Base Enums
    • Classes

The inheritance of the AOT Classes also exist in the c# code also the garbage collection issue is solved

The blue blocks are generated, the red block are part of the base project


code example of using the type safe interface
using System;
using System.Collections.Generic;
using System.Text;
using AxWrapper.BaseEnums;
using AxWrapper.Tables;
using AxWrapper.Classes;
using AxWrapper.Connection;
using Microsoft.Dynamics.BusinessConnectorNet;

namespace demo
{
    class Program
    {
        static void Main(string[] args)
        {
            Axapta ax = AxWrapper.Connection.AXConnectionSingelton.Instance().connection();
            ax.LogonAs(Environment.UserName, "", null, "CEU", "", "", ""); //connect with singelton is needed for the wrapper classes
            ax.TTSBegin();
            custtableWrapper custTable = custtableWrapper.findAX("00001004", true);//static function
            custTable.nameField = "Whatever"; //field
            custTable.getsettledateAX(_settledateprinc._dateofpayment);    //base enums
            custTable.update();
            ax.TTSCommit();

            //ledger journal
            ax.TTSBegin();
            ledgerjournalnameWrapper ledgerjournalName = new ledgerjournalnameWrapper();
            ledgerjournaltableWrapper ledgerjournalTable = new ledgerjournaltableWrapper();
            ledgerjournalName.common.ExecuteStmt("Select firstonly from %1 where %1.journalType == 0"); //select statement on table
            ledgerjournalTable.journalnameField  = ledgerjournalName.journalnameField; //assign table field to other table field
            ledgerjournalTable.initfromledgerjournalnameAX();   //call method on table
            ledgerjournalTable.nameField = "C# generated Journal";
            ledgerjournalTable.insert();

            numberseqWrapper    numberseq = numberseqWrapper.newgetnumfromcodeAX(ledgerjournalName.voucherseriesField);

            ledgerjournaltransWrapper ledgerjournalTrans = new ledgerjournaltransWrapper();
            ledgerjournalTrans.voucherField             = numberseq.voucherAX();
            ledgerjournalTrans.journalnumField          = ledgerjournalTable.journalnumField;
            ledgerjournalTrans.currencycodeField        = "EUR";
            ledgerjournalTrans.exchrateField            = currencyWrapper.exchrateAX(ledgerjournalTrans.currencycodeField); //static table function returns a record. the  currencycodeField of that record assigned.
            ledgerjournalTrans.accounttypeField         = _ledgerjournalactype._ledger; //basenum
            ledgerjournalTrans.accountnumField          = "57210";
            ledgerjournalTrans.amountcurdebitField      = 102.00;
            ledgerjournalTrans.transdateField           = DateTime.Now;
            ledgerjournalTrans.txtField                 = "Room Stay";
            ledgerjournalTrans.offsetaccounttypeField   = _ledgerjournalactype._ledger;//basenum
            ledgerjournalTrans.offsetaccountField       = "18110";
            ledgerjournalTrans.insert();
 
            ledgerjournalcheckpostWrapper ledgerJournalCheckPost = ledgerjournalcheckpostWrapper.newledgerjournaltableAX(ledgerjournalTable.common,_noyes._yes); //call static class method with unwrapper ledgerjournalTable record  
            ledgerJournalCheckPost.runAX();
     
            ax.TTSCommit();
        }
    }
}

aditional information

Parameter overloading:
It works for Boolean and base enum base parameters or return types. So a method with return type Boolean can be overloaded with return type yesno.

Base class
ABC retunBaseEnum() 
{ 
    return ABC::A; 
} 
Derived class
ABCModel retunBaseEnum() 
{ 
    return ABCModel::Link; 
}

If we have to convert this to C#, the method of the base class becomes virtual. But the derived method can’t be of type override. Even virtual new is wrong. According to C# the derived method should be virtual.

Optional parameters and inheritance:
Consider the following X++ code:
Base class
void optionalParaMeter(int _a, int _b = 0) 
{ 
} 

Derived class
void optionalParaMeter(int _a, int _b, int _c = 0) 
{ 
}

If we translate this code to c#, we get 2 methods in our base class. Virtal void optionalParaMeter(int a) and Virtal void optionalParaMeter(int a, int b ). This is acceptable code. The next step is the derived method. C# will looks like void optionalParaMeter(int a, int b) and void optionalParaMeter(int a, int b, int c). But now we get in trouble as they both need to be of type overload, but void optionalParaMeter(int a, int b, int _c) can’t be of type overload because this one does not exist in the base class. So we get a new virtual function and an override function.

Last edited Feb 3, 2009 at 1:02 PM by wenni057, version 16