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