Notifications
Announcements
No record found.
Hi,
Is there a way we can add a delegate to a static method in AX.
Thanks in advance
*This post is locked for comments
Thanks Martin.
So does a delegate for a static method need to be declared static as well.
For example:
class Example
{
delegate static void testDelegate(EventHandlerResult res){}
static void someMethod()
-- some code
// my extension code
Example::testDelegate(new EventHandlerResult ());
}
Please suggest if this is the right method to call a delegate from a static method. Thanks in advance.
You can use static delegates, although it is a bit dangerous design. When you start using static members like this, you must think about implications of multi-threading and potential impact on garbage collection. I strongly recommend you start using objects instead of static methods and static events - it's safer and easier to extend in future. Even using a singleton object is much better than static members.
But if you have a good reason to do it (and you plan how to avoid problems with the static nature of such a design), you can declare your delegate like static delegate void testDelegate(...).
Yes you should use a static delegate. Initialize EventHandlerResult, pass the variable in delegate as parameter instead of new EventHandlerResult() to get the results.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Priya_K 4
Martin Dráb 4 Most Valuable Professional
Ali Zaidi 2