Previous Topic Next topic Print topic


NETJVM 

Custom Attributes

Custom attributes are used to provide additional information about elements within your program. Much of the syntax used in a COBOL program describes program elements, such as the visibility of methods and fields (PUBLIC, PRIVATE, PROTECTED, etc.). All these descriptions are embedded as ‘Metadata’ into the dll or exe file output by the Compiler, and can be interrogated by other programs using Reflection. Custom attributes are a way of adding additional metadata to program elements in a way that is open ended and unlimited. Custom attributes are attached to COBOL items using the CUSTOM-ATTRIBUTE reserved word.

Custom attributes may be used to describe methods, data items, properties, events, delegates, method parameters, assemblies, classes and method return values.

The arguments you specify for the attribute are of two types:

For example:

 01 a binary-long attribute xml("UpperB").

The ordinary parameters used in the attribute specification must match a constructor defined by the attribute. In the example above, the constructor expects a single parameter of type string.

As another example:

custom-attribute is webservice("Description"="My service")

The named parameters must match properties defined by the attribute. In this example, Description is a property of type string defined for the custom attribute class webservice.

The attributes supported in COBOL are broadly similar to annotations supported in other languages for JVM.

Previous Topic Next topic Print topic