General X++ Development
How do I declare class-level variables in an extension class?
How do I declare class-level variables in an extension class?
1 answer
Write an answerYes. Class augmentation can add instance state to the effective class.
[ExtensionOf(classStr(MyClass))]
final class MyClass_XppForge_Extension
{
private int xppForgeCounter;
public void xppForgeIncrementCounter()
{
xppForgeCounter++;
}
}That value belongs to that object instance. It is not persisted anywhere.
One thing I would not do is use generic names like myCounter in real extension code. Extension members share the effective class namespace, so give new methods and variables names that are unlikely to collide with Microsoft or another extension later.
Know the solution?
Sign in to contribute an answer and build your community reputation.
Sign in to answer