Override of a Method

The platform provides a way to override a method of a business logic controller (BLC). We recommend that you keep the following guidelines in mind when you are defining the override of such a method:

  • You should declare it as public.
  • You should not declare it as virtual.
  • You should add a comment to its declaration by using the cref property of the <see> XML tag. The value of the cref property should reference the original method that you are overriding. Note that this comment should not be included within the <summary> tag, which is used to provide the description of a method.
  • If the override of the method contains a base delegate parameter, you should declare this parameter last in the list of parameters. The name of the parameter should begin with base_, followed by the name of the method, as shown in the following code example.
    /// Overrides <see cref="WorksheetPicking.IsWorksheetMode(string)"/>
    [PXOverride]
    public bool IsWorksheetMode(string modeCode, Func<string, bool> base_IsWorksheetMode)
    

Suppose that you need to override the PrePersist method of the BaseBLC class, which is defined in the code below.


public class BaseBLC : PXGraph<BaseBLC>
{
    protected override bool PrePersist()
    {
        if (!base.PrePersist())
          return false;
        ...
    }
}

You can override the method within a BLC extension as follows.


public class BaseBLC_Extension : PXGraphExtension<BaseBLC>
{
    /// Overrides <see cref="BaseBLC.PrePersist()"/>
    [PXOverride]
    public bool PrePersist(Func<bool> base_PrePersist)
    {
      if (!base_PrePersist())
        return false;
      ...
    }
}

The graph extension should include the declaration of the base delegate parameter, the PXOverride attribute, and the overridden method, which invokes the base delegate parameter, as the code above shows.

Because the PXOverride attribute on the declaration of the method is included in the graph extension, it forces the system to override the original method in the graph instance. Otherwise, both the base method and the overridden method will be invoked.