Skip to content

Latest commit

 

History

History
93 lines (79 loc) · 3.55 KB

File metadata and controls

93 lines (79 loc) · 3.55 KB

PX1096

This document describes the PX1096 diagnostic.

Summary

Code Short Description Type Code Fix
PX1096 The signature of a method with the PXOverride attribute must match the overridden method. Error Unavailable

Diagnostic Description

The signature of a method with the PXOverride attribute must match the overridden method. The signatures of the overridden and overriding methods must comply with one of the following rules:

  • The signatures of both methods are identical. Note, that the use of this mechanism is currently discouraged by Acumatica best practices.
  • The signatures of both methods are identical, except that the overriding method has one additional parameter, which is a delegate that points to the base method. In this scenario, the delegate signature must also match the overridden method.

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 virtual, abstract, or override.
  • 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 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.
  • The names of the derived method and the base method must match.

Example of Correct Code with Base Delegate

The following example demonstrates the correct override of a method with a base method delegate.

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, the delegate signature does not correspond to the signature of the base method.

public class MyGraph : PXGraph<MyGraph>
{
}

public class BaseGraphExtension : PXGraphExtension<MyGraph>
{
	public virtual int Add(int x, string y, bool z)
	{
		return x + Convert.ToInt32(y);
	}
}

public class DerivedGraphExtension : PXGraphExtension<BaseGraphExtension, MyGraph>
{
	/// Overrides <seealso cref="BaseGraphExtension.Add(int, string, bool)"/>
	[PXOverride]
	public int Add(int x, string y, bool z, Func<int, string, int> base_Add)
	{
		if (x < 10 && z)
		{
			return x + Convert.ToInt32(y) * 2;
		}
		
		return base_Add(x, y);
	}
}

Related Articles