Writing your own automation using C#
C/AL provides almost everything to meet our client's requirements. Sometimes though, we may need to extend the scope of C/AL to take care of some complex requirements. In this recipe, we will see an example of how to develop a basic .NET application, and more importantly, how to use it within NAV.
How to do it...
Let's get started by creating a new
Class Library
project in Visual Studio and follow the steps.Create a new file with the following code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace NAVAdd { [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("NAVAdd")] [ComVisible(true)] public class NAVAdd { public int Add(int a, int b) { return a + b; } } }
View the properties for the project.
Then on the Application tab, set the Assembly name to NAVAdd.
After that, on the Build* tab, set the Register for COM interop property to true (checked...