このヘルプでは、COBOL、C#、VB.NET の間にある属性処理方法の相違点について説明します。
*> Define custom attributes on a class
class-id. MyClass
attribute WebService(name Description = "My service")
attribute Obsolete.
*> Define custom attributes on a field...
01 a binary-long attribute XmlAttribute("UpperB")
attribute Obsolete.
*> Define custom attributes on a property...
*> Note that in this case, the custom attributes must follow
*> the reserved word PROPERTY.
01 b binary-long property
attribute XmlAttribute("UpperB")
attribute Obsolete.
*> Define custom attributes on an event...
*> Note that in this case, the custom attributes must follow
*> the reserved word EVENT.
01 d type fred event
attribute Obsolete.
*> Define custom attributes on a method...
method-id main attribute Obsolete.
*> Define custom attributes on parameters and returns
method-id Stat.
procedure division using l1 as binary-long
*> Define custom attributes on a method parameter...
attribute CLSCompliant(true)
attribute MarshalAs(3)
returning l2 as binary-long
*> Define custom attributes on a method return value...
attribute CLSCompliant(true)
attribute MarshalAs(2).
*> Define custom attributes on a property...
method-id. set property prop
attribute Obsolete.
*> Define custom attribute on a delegate...
delegate-id fred attribute Obsolete.
procedure division using l1 as binary-long.
end delegate fred.
// Define custom attribute on a class
[WebService(Description = "MyService")]
[Obsolete]
class MyClass
{
// Define custom attributes on a field
[XmlAttribute("UpperB")]
[Obsolete]
long a;
// Define custom attribute on a property
private string prop;
[Obsolete]
public string b
{
[return:XmlAttribute("UpperB")]
get { return prop; }
[value:XmlAttribute("UpperB")]
set { prop = value; }
}
// Define custom attribute on an event
[Obsolete]
public event fred d;
// Define custom attribute on a method
[Obsolete]
public void main()
{
}
// Define custom attributes on parameters and returns
[return:CLSCompliant(true)]
[return:MarshalAs(2)]
public long Stat([CLSCompliant(true)][MarshalAs(3)]long l1)
{
return 12;
}
// Define custom attributes on a property
[Obsolete]
public string b
{
set { prop = value; }
}
// Define custom attributes on a delegate
[Obsolete]
public delegate void fred(long l1);
}
' Define custom attributes on a class
<WebService(Description:="Common Server Variables"> _
<Obsolete()> _
Public Class Class1
End Class
' Define custom attributes on a field...
<XmlAttribute("UpperB")> _
<Obsolete()> _
Public a As Integer
' Define custom attributes on a property...
<XmlAttribute("UpperB")> _
<Obsolete()> _
Property b As Integer
' Define custom attributes on an event...
<Obsolete()> _
Event MsgArrivedEvent As MsgArrivedEventHandler
' Define custom attributes on a method...
<Obsolete()> _
Sub main()
End Sub
' Define custom attributes on parameters and returns
Function Stat _
( _
<CLSCompliant(True)> _
<MarchalAs(3)> ByVal l1 As Integer _
) _
As <CLSCompliant(True)> <MarchalAs(2)> Integer
' Define custom attributes on a property...
<Obsolete(True)> _
Public Property prop() As String
Set(ByVal value As String)
' Define custom attribute on a delegate...
<Obsolete()> _
Delegate Sub Fred(ByVal l1 As Integer)
これらの例の一部は、ハーディング大学コンピュータ サイエンス学部の Frank McCown 博士が作成したもので、クリエイティブ コモンズ ライセンスに基づいて使用が許可されています。