CLR interop - accessing via

I’m pretty sure the answer to this is ‘no’, but I figure I’ll ask here anyway…

Is there any way, in CLR interop, from X++, to access and set values via an indexer?

I’m looking at using a .Net DLL for reading and writing spreadsheet files, and cell values can be set like this (in C#):

worksheet.Cells[1, 1].Value = “ID”;

worksheet.Cells[“A2”].Value = 12001;

I can’t figure out any way to access the indexer from X++. I’m thinking that, if I really want to use this DLL, I will have to write a wrapper for it in C# that wraps the indexer calls in a simple method that can be called from X++. Maybe I’m missing something though. Any helpful hints would be appreciated!

X++ doesn’t have any support for indexers, but you still can access the underlying indexed property through its setter method: set_Item(). Indexers are just a nicer way to call these underlying CLR methods.

Thanks. I have figured out that I can do something like this:

range = worksheet.get_Cells();
range.set_Address(“A1”);
range.set_Value(“this is A1”);

But that’s a lot more verbose than in C#. I’m finding that, in general, using any non-trivial library written in C# from X++ requires a bit of work.

I sure do miss stuff like indexers and other syntactic sugar when I’m working in X++!

[:)]

It is much more verbose, it doesn’t support even more important features (e.g. generics) but it’s still absolutely great. Do you know how difficult live was before .NET Interop? :slight_smile:

I indeed tend to write logic in C# and expose a simplified interface if there is more than just few calls to .NET objects (or I need some special features, of course) - especially in AX2012, where adding VS projects to AOT really simplifies one’s live. As always, you have to choose the right tool for the task.