This document describes the PX1101 diagnostic.
| Code | Short Description | Type | Code Fix |
|---|---|---|---|
| PX1101 | The additional delegate parameter of the method with the PXOverride attribute must have the same signature as the base method. |
Error | Available |
Acumatica Framework provides a way to override virtual methods in graphs and graph extensions by declaring a method with the PXOverride attribute. The method must have the same name, return type, and parameters as the base method plus an additional parameter.
This last parameter is a delegate that represents the base method. The purpose of this delegate is to provide developers with control of calls to the base method from the overriding method.
The PX1101 diagnostic ensures that the signature of the delegate parameter matches the signature of the base method.
The code fix for the PX1101 diagnostic corrects the type of the delegate parameter to match the signature of the base method. It also changes the name of the delegate parameter according to the naming conventions of Acumatica Framework.
The convention is to name the delegate parameter as base_<MethodName>, where <MethodName> is the name of the base method being overridden.
The code fix does not support methods that accept an input value or the return result by reference instead of by value, such as:
- Methods with the
ref,out,in, orref readonlyparameters - Methods with the
refandref readonlyreturn types
Such methods have to be fixed manually.
- The overriding method must be declared in a graph extension.
- The overriding method must have the
publicaccess modifier. - The overriding method cannot be
virtual,abstract, oroverride. - The overriding method should not be
static. - The overriding method cannot be a generic method.
- The overriding method should always declare an additional delegate parameter.
- The overriding method should declare an XML documentation comment with a reference to the base method in the format
/// Overrides <seealso cref="{Base method}">. - The signature of the overriding method must be compatible with the signature of the overridden base method. The names of the derived method and the base method must match.
- The base method must be
virtual(have eithervirtualoroverridemodifiers). - The base method must have one of the following accessibility levels:
public,protected, orprotected internal.
The following example demonstrates the correct declaration of the PXOverride method with an additional delegate parameter.
public class MyGraph : PXGraph<MyGraph>
{
}
public class BaseGraphExtension : PXGraphExtension<MyGraph>
{
public virtual int Add(int x, string y)
{
return x + Convert.ToInt32(y);
}
}
public class DerivedGraphExtension : PXGraphExtension<BaseGraphExtension, MyGraph>
{
/// Overrides <seealso cref="BaseGraphExtension.Add(int, string)"/>
[PXOverride]
public int Add(int x, string y, Func<int, string, int> base_Add)
{
if (x < 10)
{
return x + Convert.ToInt32(y) * 2;
}
return base_Add(x, y);
}
}In the following example, PXOverride methods are declared with incorrect additional delegate parameters with signatures that do not match the corresponding base methods.
public class MyGraph : PXGraph<MyGraph>
{
protected virtual void UpdateBalances()
{
// Implementation
}
}
public class BaseGraphExtension : PXGraphExtension<MyGraph>
{
public virtual int Add(int x, string y)
{
return x + Convert.ToInt32(y);
}
}
public class DerivedGraphExtension : PXGraphExtension<BaseGraphExtension, MyGraph>
{
/// Overrides <seealso cref="BaseGraphExtension.Add(int, string)"/>
[PXOverride]
public int Add(int x, string y, Func<int, object, int> base_Add) // Report PX1101
{
if (x < 10)
{
return x + Convert.ToInt32(y) * 2;
}
return base_Add(x, y);
}
/// Overrides <seealso cref="MyGraph.UpdateBalances()"/>
[PXOverride]
public void UpdateBalances(Action<string> base_UpdateBalances) // Report PX1101
{
// Implementation
}
}