Today I would like to brefily talk about documentation comments in Business Central.
APPLIES TO: Business Central 2020 release wave 2 and later (BC17)
In Dynamics 365 Business Central, you can add documentation to your code by including XML elements in special comment fields directly in the source code before the block of code that the comment refers to.
The documentation comment must immediately precede a user-defined type that it annotates, for example a codeunit, table, or interface, or a member such as a field or method. The syntax for adding XML comments in your code is triple slashes
/// followed by one of the supported XML tags. There is IntelliSense support for writing documentation comments. Most importantly providing a template documentation comment when writing the third slash in the triple slash.
We can look at the standard codeunit.
codeunit 8901 “Email”
When we call it:
PS: In overloaded procedures
Let’s look at another example.
codeunit 1284 “Password Handler”
Supported XML tags
The following table lists the XML elements that are supported for AL.
|Top-level XML Tag||Description||Syntax|
|A summary of the object|
|Used in method declarations to describe one or more parameters defined in the method. For each parameter, specify the name and a description.|
|Used in method declarations to describe the return value of the method.|
|Used to specify an example of how to use a given codeunit or object.|
|Used to supplement information given in the |
|Formatting XML Tag||Description||Syntax|
|Specifies a reference to a parameter in a |
|Allows structuring text inside a |
|Allows formatting text as bold inside a top-level tag.|
|Allows formatting text as italic inside a top-level tag.|
|Specifies that text within a description should be marked as code inside a top-level tag.|
|Specifies that multiline text within a description should be marked as code inside a top-level tag.|
|Specifies a list formatted as a bulleted or numbered list, or as a table in a |
For special symbols, such as angle brackets, to appear in text of a documentation comment, use the HTML encoding of
> which is
> respectively. The following example illustrates how.
Code comments improve the readability of the code that you have developed and they are very useful for anyone modifying or maintaining that code. Furthermore, code comments form the basis of auto-generated documentation. Great code comments must do the following:
- Never state the obvious.
- Write a meaningful comment, use precise wording to describe why.
- Imagine yourself in the shoes of the developer using this piece of code, what would you want to know?
- For properties and methods, use active wording such as Sets…, Gets…, and Specifies…, and then explain what it does.
- List all pre-conditions for your parameters (cannot be null, must be within a certain range, and so on).
- List any post-conditions that could influence how callers deal with return values.
- List any exceptions the method may throw (and under what circumstances).
- If similar methods exist, explain the differences between them.
- Call attention to anything unexpected (such as modifying global state).
- Enumerate any side-effects, if there are any.
- Be consistent.
- Be concise.
- Make sure that your comments are reviewed.
Adding XML Documentation can greatly improve the readability of our code. Give it a try!!!😁
You can find more details about XML Comments in Code in MS Docs.
PS: If you have the the AL XML Documentation extension installed.
You may see the following message.
XML documentation is expected for Procedure TestPermission.
XML documentation is expected for Object Lab Book.
You can disable it in the following settings, or change it to Warning or Error.
Check Object Documentation Information Level:
Check Procedure Documentation Information Level
Hope this will help.