Monday, June 2, 2008

.NET enumerations in Dynamics AX

As you know starting from DAX 4.0 .NET interoperability was introduced.
You can easily instantiate .NET classes either likewise COM or by directly calling constructor method:

Microsoft.Office.Interop.Outlook._Application outlookApplication =
new Microsoft.Office.Interop.Outlook.ApplicationClass();

it is the same with

Microsoft.Office.Interop.Outlook._Application outlookApplication =
new CLRObject("Microsoft.Office.Interop.Outlook.ApplicationClass");

Although usage of .NET objects is quiet common to COM, you cannot pass enum parameter to .NET object as int or str

Instead of doing it you have to initialize it this way:

Microsoft.Office.Interop.Outlook.OlItemType olAppointmentItem = CLRInterop::parseClrEnum('Microsoft.Office.Interop.Outlook.OlItemType',
'olAppointmentItem'
);

Here you're initializing type of new Outlook item with type Appointment.

This inconvenient trick should be held every time you want to initialize enum parameter. Anyway it is more convenient than defining macro values like is done for COM enumerations.

1 comment:

Baltazar said...

Thanks! It was helpful :)