web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Dynamics 365 for Operations: Class extensions and Chain of Command (COC)-Next keyword

Vishal Tiwari Profile Picture Vishal Tiwari 393
The functionality of extension classes (also known as class augmentation) is being improved to allow developers to wrap logic around methods defined in a base class. This allows extending the logic of public and protected methods without the need to use event handlers. When you wrap a method, you can also access other public and protected methods and variables of the class. This way, you can start transactions and easily manage state variables associated with your class.
Class Student
{
    real studentAge(int arg)
   {
    …
    }
}
It is now possible to extend the functionality of method1 using an extension class by reusing the same name to add pre-and post-logic to it.
[ExtensionOf(ClassStr(Student))]
class Student_Extension
{
    real studentAge (int arg)
    {
     var s = next studentAge(arg + 4);
    
      return s;
    }
}

Wrapping studentAge and the required use of the next keyword creates a Chain of Command (CoC) for the method. Here is what happens when the following code executes.
Student c = new Student ();
Print c. studentAge (33);

The system will find any method that wraps studentAge. It will randomly execute one of these methods (say, studentAge of the Student _Extension class). When the call to next studentAge() occurs the system will randomly pick another method in the CoC or call the original implementation if none exist.

This was originally posted here.

Comments

*This post is locked for comments