Export (0) Print
Expand All

Best Practices for Local Functions [AX 2012]

Updated: December 2, 2011

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
}

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

Community Additions

ADD
Show:
© 2015 Microsoft