Previous Topic Next topic Print topic


NETJVM 

Extension Methods in Managed COBOL

Extension methods enable you to add methods to existing types without the need to edit or recompile the code. Extension methods appear as additional methods available on an object instance while they are implemented elsewhere.

To declare an extension method, you use the EXTENSION keyword. The extension method must be a static method in a static class that is not nested or generic.

       class-id MyExtension static.
       method-id MyExtensionMethod [static] [is] extension.
       local-storage section.
       procedure division using myName as type classToExtend
                       returning myReturnName as type returnType.
           set myReturnName to my code...
           goback.
       end method.
       end class.

There is no special syntax for calling extension methods from managed COBOL. You consume an extension method in the same way as any other method, except you specify the first parameter as the type of the method, using this syntax:

parameter-1::method-name(more parameters)
Previous Topic Next topic Print topic