*> 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.
カスタム属性のサンプルも参照してください。このサンプルは、[スタート > すべてのプログラム > Micro Focus Enterprise Developer > サンプル > Visual COBOL サンプル] の [COBOL for .NET] の下にあります。
属性は、次の内容を使用して指定できます。
01 a binary-long attribute xml("UpperB").
attribute WebService(NAME Description="My service")
属性 (カスタム属性とも呼ばれる) は、プログラム内の要素に関する追加情報を提供する場合に使用されます。属性を使用して、メソッド、データ項目、プロパティ、イベント、デリゲート、メソッド パラメーター、アセンブリ、クラス、メソッド戻り値を記述することができます。
COBOL プログラムで使用される構文の多くは、メソッドやフィールドの可視性 (PUBLIC、PRIVATE、PROTECTED など) といったプログラム要素を記述します。これらの記述はすべて、コンパイラーから出力される dll または exe ファイルにメタデータとして埋め込まれ、リフレクションを使用して他のプログラムから問い合わせを行うことができる。属性は、無期限かつ無制限に追加のメタデータをプログラム要素に追加する方法です。
指定された属性は、エントリの主体を記述するメタデータの一部になり、リフレクタで表示できます。