This document describes the PX1097 diagnostic.
| Code | Short Description | Type | Code Fix |
|---|---|---|---|
| PX1097 | Methods with the PXOverride attribute must be public and non-virtual. |
Error | Available |
A method with the PXOverride attribute must be declared as public and must not be virtual, abstract, or override:
- Methods with the
PXOverrideattribute must be declared with thepublicaccessibility due to the requirements of Acumatica Framework. Currently, Acumatica Framework supports only public methods with thePXOverrideattribute. - Methods with the
PXOverrideattribute must be non-virtual. Such methods cannot havevirtual,abstract, oroverridemodifiers. Acumatica Framework does not support combination of thePXOverridemechanism with regular C# overrides.
- The overriding method must be declared in a graph extension.
- 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 code fix for the PX1097 diagnostic changes the accessibility of the method with the PXOverride attribute to public and removes any virtual modifiers from the method declaration.
The code fix cannot be applied to methods with the override modifier, because such change would break the compatibility of the method with the base method it overrides. In this case, the code fix is not available.
The code fix can change the accessibility of the abstract method with the PXOverride attribute to public but it cannot make such method non-virtual.
Such change would introduce a compilation error since only abstract methods can be declared without a body.
The following example demonstrates the correct declaration of the PXOverride method.
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 either declared as virtual or do not have the public accessibility.
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 virtual 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);
}
/// Overrides <seealso cref="MyGraph.UpdateBalances()"/>
[PXOverride]
protected void UpdateBalances()
{
// Implementation
}
}