Naming conventions for Delegates and Event handlers

This topic provides the naming convention for delegates and event handlers when using X++.

Delegate Naming Conventions

When you name a delegate, follow the general Naming Conventions for X++ and the Naming Conventions for Methods. The following list describes additional naming guidelines for delegates.

  • The two components of the name should be a noun (for example invoice) and a verb (for example opening or opened). An example is invoiceOpened. When the class name is a noun, the noun can be omitted from the delegate name. For example, Invoice\opened().

    Use present tense for logic that runs before an event occurs (end with ing)

    Use past tense for logic that runs after an event occurs (end with ed)

  • The following example illustrates definitions of two delegates creating and created in the Invoice class that is a noun.

    class Invoice
    {
        …
        delegate void creating(object sender, InvoiceEventArgs args) {}
        delegate void created(object sender, InvoiceEventArgs args) {} 
    }
           
    

Event Handler Naming Conventions

Event handlers must have a name with the suffix EventHandler. The following example illustrates names that consist of the delegate name and the EventHandler suffix.

    void createdEventHandler(object sender, InvoiceEventArgs args)
    void invoiceCreatedEventHandler(object sender, InvoiceEventArgs args)