Best Practices for Local Functions

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Use private class methods instead of local functions (local methods) wherever possible. Local functions cannot be overridden, overlayered, or reused.

Local functions follow all other standards for methods—name, style, layout, and so on. However, local functions cannot be used from outside the method where they are defined.

Local function declarations should be indented to the same level as the types in the variable declarations. Like other declarations, they should be at the top of the code block and separated from other code by a semicolon (;) on a blank line. An example follows.

    protected void setValueQty()
    {
        InventTransPosting  inventTransPosting;
        InventSum           inventSum;
        InventDim           inventDim;
    
        void addPhysical()
        {
            if (inventTransPosting.isPosted)
                ...
        }
        ; // Semicolon at the end of the declarations
          // ... More code
    }

See also

Best Practices for Methods

Best Practices for Parameters

Best Practices for Table Methods

Best Practices for Method Modifiers

Naming Conventions: Methods

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.