Created On:  09 January 2012

Problem:

What is the equivalent syntax in Visual COBOL to this fragment of code in C# that declares a property name Message that has a couple of attributes defined?

        [Category("Data")]
        [Description("Alert Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

Resolution:

You can do this in a couple of ways. You will have to add the following namespace import directive to the top of the program or in the project Properties:

$set ilusing"System.ComponentModel"

Since it is defining a simple property that only sets or gets the value of a field you could do this as follows:

01 wsmessage string property as "Message"
       attribute Category("Data")
       attribute Description("Alert Message").


This automatically generates the get and set methods for you.

Or if you needed to change the get or set methods of the property to do something more advanced then you could specify this as follows:

01 wsmessage string.
...
method-id set property wsMessage as "Message"
     attribute Category("Data")
     attribute Description("Alert Message").
procedure division using by value the-value as string.
     set wsmessage to the-value
end method.
       
method-id get property wsMessage as "Message"
     attribute Category("Data")
     attribute Description("Alert Message").
procedure division returning the-value as string.
     set the-value to wsmessage
end method.

This is covered in the two example programs under C:\Users\Public\Documents\Micro Focus\Visual COBOL 2010\Samples\COBOL for .NET\ called:
CustomAttributes
Properties

You can also find these by opening the Visual COBOL Samples Browser from Start Menu-->All Programs-->Micro Focus Visual COBOL 2010-->Visual COBOL Samples under the COBOL for .NET category.