The views and opinions expressed in this blog are those solely of the author(s) and do not necessarily reflect Microsoft’s current policy, position, or branding. For official announcements and guidance on Dynamics 365 apps and services, please visit the Microsoft Dynamics 365 Blog.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 release wave 1 Discover the latest updates and new features to Dynamics 365 planned through September 2020
Release overview guides and videos Release Plan | Preview 2020 Release Wave 1 Timeline
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
A friend asked my by e-mail today about a problem he encountered with DotNet interop: how to access a property of an object, if the property name matches a reserved word in NAV. A simplest example is from the Microsoft.Dynamics.Nav.SMTP.SmtpMessage class that comes bundled with NAV 2013.
Consider this piece of code:
Mail := Mail.SmtpMessage;
Mail.To := 'email@example.com';
If you try to compile this, it will fail. It’s simple: the To property name is invalid in the C/AL context, because it is a reserved word.
So, how do you fix it?
The answer is: reflection.
Reflection is a built-in functionality into the Framework Class Library that allows you to access meta-information about .NET types, and to dynamically manage that information. I know this is a lousy definition, and all my .NET black-belt ninja friends will now laugh in my face, but I wanted to keep the definition simple for my C/AL friends who don’t have extensive .NET experience.
So, in principle, this is what you must do if you have a situation such as this:
Let’s translate it to C/AL now. First, declare a variable of System.Type type from the mscorlib assembly. Then, write this code:
Mail := Mail.SmtpMessage;
//Mail.To := 'firstname.lastname@example.org';
Type := GETDOTNETTYPE(Mail);
And that’s it. Try it and see if it works.
You can use the same principle with methods as well. I won’t write any code examples here, because I’ve already posted some examples that showcase this principle. Check the Try..Catch demo from my TechDays 2014 Black Belt session in this post.
I hope this helps. Please, let me know!
Business Applications communities