Skip to content

Latest commit

 

History

History
114 lines (95 loc) · 3.36 KB

PX1096.md

File metadata and controls

114 lines (95 loc) · 3.36 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.
  • 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

  • The overriding method cannot be static.
  • The overriding method cannot be generic.
  • The base method must be a member of graph extension—that is, a class that derives from PXGraphExtension.
  • The base method must be virtual (have either the virtual signature or the override signature).
  • 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

The following example demonstrates the correct override of a method using the PXOverride attribute.

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>
{
	[PXOverride]
	public virtual int Add(int x, string y)
	{
		return x + Convert.ToInt32(y) * 2;
	}
}

Example of Correct Code with 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>
{
	[PXOverride]
	public virtual int Add(int x, string y, Func<int, string, int> del)
	{
		if (x < 10)
		{
			return x + Convert.ToInt32(y) * 2;
		}
		
		return del(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>
{
	[PXOverride]
	public virtual int Add(int x, string y, bool z, Func<int, string, int> del)
	{
		if (x < 10 && z)
		{
			return x + Convert.ToInt32(y) * 2;
		}
		
		return del(x, y);
	}
}

Related Articles

To Override a Virtual Method PXOverrideAttribute