Announcements
I'm writing some code related to service bus in X++.
In part of my code I need to read BrokeredMessage.Properties (https://docs.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.properties?view=azure-dotnet) which is of type System.Collections.Generic.IDictionary<string,object>
Within X++ I can reference this as System.Collections.Generic.IDictionary`2 however the ` creates a compilation error.
Any idea how I can go about this? I currently am using var, but then I do not get the intellisense.
Hi Martin,
you're absolutely right about this. The error does occur at compile time. I was under the wrong impression that since Intellisense half works (some methods show up while others don't), that var, in Dynamics, was choosing a more generic type.
Thanks for pointing that out. I think its another note of improvement for the guys working on the IDE.
That's not correct - var doesn't mean weakly typing (as with anytype or so) and you'll get compile-time checking. It's true that IntelliSense often have a problem with it. Using var means that the type is detected by compiler, not that the type is unknown. Could you test it once more, please? For example, try to compile this:
var properties = message.Properties; properties.Abcdefg();
The compiler should tell you that no such a method exists.
I'm not saying that you can't work with generic collections in older versions, but you can't do it in this way. My recommendation is using non-generic interfaces there, such as IEnumerable if you want to iterate the collection. You can also declare the type is CLRObject, but then you really don't get any compile-time checking.
Thanks for the information.
I suspected it couldn't be done in older versions but I wanted confirmation.
Regarding F&O, as I mentioned, I have successfully used var but it makes it an object type so I don't get Intellisense or compile time checks.. I am interested to know if there is an alternative.
In F&O, simply use var as the type name:
var properties = message.Properties;
But you can't do that in older versions. If you need a solution for F&O, we're done. If you need a solutions for older versions, this is completely useless to you and we'll need to discuss other ways.
I left the version part open on purpose as I'm curious how it would be done both in F&O and in Ax. Most importantly in F&O though.
Hi Normbert, I moved your question from Dynamics 365 General Forum here to the AX forum, but I don't which version you're talking about and whether it shouldn't actually be in an F&O forum. Please clarify.
Your options depend on the version.
André Arnaud de Cal...
294,120
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator