This document describes the PX1096 diagnostic.
Code | Short Description | Type | Code Fix |
---|---|---|---|
PX1096 | The signature of a method with the PXOverride attribute must match the overridden method. |
Error | Unavailable |
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.
- 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.
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;
}
}
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);
}
}
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);
}
}