Skip to content

Latest commit

 

History

History
107 lines (92 loc) · 4.37 KB

File metadata and controls

107 lines (92 loc) · 4.37 KB

PX1097

This document describes the PX1097 diagnostic.

Summary

Code Short Description Type Code Fix
PX1097 Methods with the PXOverride attribute must be public and non-virtual. Error Available

Diagnostic Description

A method with the PXOverride attribute must be declared as public and must not be virtual, abstract, or override:

  • Methods with the PXOverride attribute must be declared with the public accessibility due to the requirements of Acumatica Framework. Currently, Acumatica Framework supports only public methods with the PXOverride attribute.
  • Methods with the PXOverride attribute must be non-virtual. Such methods cannot have virtual, abstract, or override modifiers. Acumatica Framework does not support combination of the PXOverride mechanism with regular C# overrides.

Further Constraints of Methods with the PXOverride Attribute

  • 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 either virtual or override modifiers).
  • The base method must have one of the following accessibility levels: public, protected, or protected internal.

Code Fix

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.

Example of Correct Code

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);
	}
}

Example of Incorrect Code

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
	}
}

Related Articles