This documentation is archived and is not being maintained.

CodeAttributeArgument Class

Represents an argument used in a metadata attribute declaration.

For a list of all members of this type, see CodeAttributeArgument Members.


[Visual Basic]
Public Class CodeAttributeArgument
public class CodeAttributeArgument
public __gc class CodeAttributeArgument
class CodeAttributeArgument

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


CodeAttributeArgument can be used to represent either the value for a single argument of an attribute constructor, or a value with which to initialize a property of the attribute.

The Value property indicates the value of the argument. The Name property, when used, indicates the name of a property of the attribute to which to assign the value.

Attribute declarations are frequently initialized with a number of arguments that are passed into the constructor of the attribute at run time. To provide arguments to the constructor for an attribute, add a CodeAttributeArgument for each argument to the Arguments collection of a CodeAttributeDeclaration. Only the Value property of each CodeAttributeArgument needs to be initialized. The order of arguments within the collection must correspond to the order of arguments in the method signature of the constructor for the attribute.

You can also set properties of the attribute that are not available through the constructor by providing a CodeAttributeArgument that indicates the name of the property to set, along with the value to set.


[Visual Basic, C#] The following code creates a CodeAttributeArgument that declares an attribute named current_page with a value of 0:

CodeTypeDeclaration class1 = new CodeTypeDeclaration("MyClass");
class1.CustomAttributes.Add( new CodeAttributeDeclaration("System.Obsolete", new CodeAttributeArgument( new CodePrimitiveExpression("This class is obsolete.") )) );
// A C# code generator produces the following source code for the preceeding example code:
// [Obsolete("This class is obsolete.")]
// public class class1 {
// }
[Visual Basic] 
Dim class1 As New CodeTypeDeclaration("MyClass")
class1.CustomAttributes.Add( Dim New CodeAttributeDeclaration("System.Obsolete", new CodeAttributeArgument( Dim New CodePrimitiveExpression("This class is obsolete.") )) )
' A Visual Basic code generator produces the following source code for the preceeding example code:
' <Obselete("This class is obsolete.")> _
' Public Class class1
' End Class

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeAttributeArgument Members | System.CodeDom Namespace | CodeAttributeDeclaration | CodeAttributeArgumentCollection