D365FO class extensions naming tool

December 12, 2019

In D365FO Microsoft introduced a new concept of extension classes, which is different from standard elements. For example, for a form, you have the form design and related X++ code as one object. But for a form extension you create a form design as one AOT object and the code related to individual form extension components as separate AOT objects(extension classes). And this creates a new problem for developers - how to name these classes.

Microsoft published some basic guidelines for naming conventions - Naming guidelines for extensions-Naming extension classes, but it seems these rules are not even used inside Microsoft teams.

The page provides some basic rules - technically extension classes are not new objects, so Suffix should be used instead of Prefix, and you need to create a distinction between objects with the same names(like form CustTable and table CustTable)

Microsoft naming guide

Some objects from the standard code follow these rules, but many of them don't. Let's check standard objects in 10.0.5 application:

public final class AppTroubleshooting_InventTable_Extension

According to the guide above it should be InventTableAppTroubleshooting_Extension

public final class BudgetReservationCreatePSN_Extension

public final class RetailStatementsPart_Extension

These two are against the rule - "Don't name the extension just _Extension."

internal final class RevRecSalesEditLines_Extension

internal final class RevRecLedgerJournalTableForm_Extension

Here "RevRec" is used as a prefix instead of a suffix, but what is more interesting that for the first element they used an additional "Form" suffix but didn't add it to the second one.

So organising a naming convention even within Microsoft teams is a quite hard task.

Why this is important

Currently, there is no combined view in Visual Studio to view the final code(that includes all applied extensions and event handlers), so proper naming convention helps you to quickly find objects and avoid code duplication(where the same logical function is implemented in two different classes).

It doesn't matter what rules you will follow, more critical is that within one project naming convention should be the same.

Solution to this problem - automatic extension class creation

First, you need to define the naming conventions for your project. Currently, 8 elements can have extension classes; you need to define naming rules for all these elements(I have seen several dev guides where only 2 or 3 types were specified).

  • Class
  • Table
  • DataEntityView
  • View
  • Form
  • FormDataField
  • FormDataSource
  • FormControl

In addition to these rules, you also need to define where to put your event handlers. Technically event handlers are static methods and can be created in any class, but you should not put these static methods to extension classes(details can be found in this article - https://daxmusings.codecrib.com/2018/06/accidental-code-extensions.html). I think the best approach to use the same names as for extensions, but with the different suffix _EventHandler, and for forms put all handlers into one class.

So totally you need to define 16 rules.

I created a setup form where you can define these naming rules and added a function to quickly specify an initial template (currently there are only two: with "_" and without).

You can adjust the default settings and save it to file

Setup form

Next step is to exclude manual work when you create extension classes. I extended my "Create extension class" add-in to automatically generate a class name based on these rules(this form can be called for any object that allows extension classes)

Create class dialog

As a result, the following class will be generated

final class CustTableForm_TST_Extension


You can download this Create class extension from the following link https://github.com/TrudAX/TRUDUtilsD365/releases. If you find that something is missing or can be improved don't hesitate to leave a comment. If you have your own rules you can also send them to me(or create a Pull request) and I will add them as an option for the default settings.

Tagged with:
Denis Trunin
Written by Denis Trunin

Get notifications about new posts on Twitter, RSS .