Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 2.9 KB

PX1041.md

File metadata and controls

46 lines (34 loc) · 2.9 KB

PX1041

This document describes the PX1041 diagnostic.

Summary

Code Short Description Type Code Fix
PX1041 Classic graph event handlers which rely on naming conventions can be converted to generic graph event handlers which have a strongly typed generic signature Information Available

Diagnostic Description

Classic graph event handlers have a weakly typed signature which relies on naming conventions. These event handlers can be converted into generic graph event handlers which have a strongly typed generic signature.

Classic event handlers are mostly used in the older code of Acumatica ERP and its customizations. Currenly, using classic event handlers is not recommended because probability of a mistake in the name can be rather high and this mistake cannot be detected during compilation. However, in some rare scenarios, classic event handlers are the only way to declare an automatically subscribed graph event handler for a cache field, for example, for cache fields dynamically generated at runtime.

Generic event handelers which have strongly typed signature provide better type safety and C# compiler checks. They can be used almost interchangeably with classic event handlers.

Therefore, we recommend to convert classic event handlers to generic event handlers. Acuminator provides a code fix which performs the conversion.

The event handler's signature cannot be safely converted to the generic one in the following scenarios related to overriding of another event handler:

  • When an event handler is a C# override of the event handler from the base class
  • When an event handler is a graph extension's method with the PXOverride attribute and this event handler overrides the event handler from the base graph or the graph extension
  • When an event handler has more than two parameters and overrides the event handler from the base graph or graph extension

In these scenarios, you need to convert all involved event handlers manually.

Example of the Classic Event Handler

protected virtual void ARInvoice_RefNbr_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
    //...
}

Example of the Generic Event Handlers

protected virtual void _(Events.FieldUpdating<ARInvoice, ARInvoice.refNbr> e) 
{
    //...
}

Related Articles

Event Handlers Types of Graph Event Handlers Naming Conventions for Event Handlers Defined in Graphs