Attributes in Managed COBOL
*> Define attributes on a class
class-id MyClass
attribute WebService(name Description = "My service")
attribute Obsolete.
*> Define attributes on a field
01 a binary-long attribute XmlAttribute("UpperB")
attribute Obsolete static.
01 b string attribute CLSCompliant(false)
*> Define attributes on a property
*> Note that in this case, the attributes must follow
*> the reserved word PROPERTY
01 b binary-long property
attribute XmlAttribute("UpperB")
attribute Obsolete static.
*> Define attributes on an event
*> Note that the attributes must follow
*> the reserved word EVENT.
01 d type fred event
attribute Obsolete static.
*> Define attributes on a method
method-id main
attribute Obsolete static.
procedure division
move 999 to a
display a
end method.
*> Define attributes on a method parameter and return type
method-id stat static.
procedure division
using by value l1 as binary-long
attribute CLSCompliant(true)
attribute MarshalAs(3)
returning l2 as binary-long
attribute CLSCompliant(true)
attribute MarshalAs(2).
move 999 to a
display a
set d to null
end method.
*> Define attributes on a property
method-id set property prop
attribute Obsolete static.
procedure division using by value l1 as binary-long.
move l1 to a
end method.
end class.
*> Define attribute on a delegate
delegate-id fred attribute Obsolete.
procedure division using by value l1 as binary-long.
end delegate.
Atttributes in C#
// C# terminology : attribute
// Define attributes on a class
[WebService(Description = "MyService")]
[Obsolete]
class MyClass
{
// Define attributes on a field
[XmlAttribute("UpperB")]
[Obsolete]
long a;
// Define attribute on a property
private string prop;
[Obsolete]
public string b
{
[return:XmlAttribute("UpperB")]
get { return prop; }
[value:XmlAttribute("UpperB")]
set { prop = value; }
}
// Define attribute on an event
[Obsolete]
public event fred d;
// Define attribute on a method
[Obsolete]
public void main()
{
}
// Define attributes on parameters and returns
[return:CLSCompliant(true)]
[return:MarshalAs(2)]
public long Stat([CLSCompliant(true)][MarshalAs(3)]long l1)
{
return 12;
}
// Define attributes on a property
[Obsolete]
public string b
{
set { prop = value; }
}
// Define attributes on a delegate
[Obsolete]
public delegate void fred(long l1);
}