属性

属性は、プログラム内の要素に関する追加情報を提供する場合に使用されます。

attribute-clause

constructor-parameters property-name = property-value

*> 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.   

属性を指定するには

属性は、次の内容を使用して指定できます。

constructor parameters
該当属性のコンストラクタのパラメーターを指定します。属性の指定で使用されるコンストラクタ パラメーターは、属性で定義されるコンストラクタと一致する必要があります。次の例では、コンストラクタは文字列タイプの単一パラメーターを予測します。
 01 a binary-long attribute xml("UpperB").
NAME property-name = property-value
指名されるパラメーターです。属性クラスで定義されるプロパティに相当します。指名されたパラメーターは、属性で定義されるプロパティと一致する必要がある。次の例では、Description は、属性クラス WebService に定義される文字列タイプのプロパティです。
attribute WebService(NAME Description="My service")

属性について

属性 (カスタム属性とも呼ばれる) は、プログラム内の要素に関する追加情報を提供する場合に使用されます。属性を使用して、メソッド、データ項目、プロパティ、イベント、デリゲート、メソッド パラメーター、アセンブリ、クラス、メソッド戻り値を記述することができます。

COBOL プログラムで使用される構文の多くは、メソッドやフィールドの可視性 (PUBLIC、PRIVATE、PROTECTED など) といったプログラム要素を記述します。これらの記述はすべて、コンパイラーから出力される dll または exe ファイルにメタデータとして埋め込まれ、リフレクションを使用して他のプログラムから問い合わせを行うことができる。属性は、無期限かつ無制限に追加のメタデータをプログラム要素に追加する方法です。

指定された属性は、エントリの主体を記述するメタデータの一部になり、リフレクタで表示できます。