Export (0) Print
Expand All

CodeAttributeArgument Class

Represents an argument used in a metadata attribute declaration.

Namespace: System.CodeDom
Assembly: System (in system.dll)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class CodeAttributeArgument
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class CodeAttributeArgument
SerializableAttribute 
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class CodeAttributeArgument
Not applicable.

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.

The following code creates a class, and adds code attributes to declare that the class is serializable and obsolete.

    // Declare a new type called Class1.
    CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");

    // Use attributes to mark the class as serializable and obsolete.
    CodeAttributeDeclaration codeAttrDecl = new CodeAttributeDeclaration(
                                                "System.Serializable");
    class1.CustomAttributes.Add(codeAttrDecl);

    CodeAttributeArgument codeAttr = new CodeAttributeArgument(
               new CodePrimitiveExpression("This class is obsolete."));
    codeAttrDecl = new CodeAttributeDeclaration("System.Obsolete", 
                                                       codeAttr);
    class1.CustomAttributes.Add(codeAttrDecl);
// A C# code generator produces the following source code for the preceeding example code:
//    [System.Serializable()]
//    [System.Obsolete("This class is obsolete.")]
//    public class Class1 {
//    }

System.Object
  System.CodeDom.CodeAttributeArgument

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft