System.CodeDom.CodeAttributeArgument Class

Assembly: System.dll
Namespace: System.CodeDom
Summary
Represents an argument used in a metadata custom attribute declaration.
C# Syntax:
[Serializable]
public class CodeAttributeArgument
Remarks
CodeAttributeArgument can be used to represent code that declares an attribute name and value. The CodeAttributeArgument.Name property is used for named arguments.

CodeAttributeArgument can be used to represent an argument of a custom metadata attribute declaration. Attribute declarations are frequently initialized with a number of arguments that are passed into the constructor of the attribute at run time. Most of the time the values are simple primitives or static field references, and only the CodeAttributeArgument.Value property needs to be initialized. However, to set properties of metadata attributes not available through the constructor, you can specify an attribute argument that is a name and value pair.

Example
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.") )) );
        

This code generates the following output:

[C#]

[Obsolete("This class is obsolete.")]

public class class1 {

}

See also:
System.CodeDom Namespace | CodeAttributeArgumentCollection

System.CodeDom.CodeAttributeArgument Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the CodeAttributeArgument class.
ctor #2 Overloaded:
.ctor(CodeExpression value)

Initializes a new instance of the CodeAttributeArgument class using the specified value.
ctor #3 Overloaded:
.ctor(string name, CodeExpression value)

Initializes a new instance of the CodeAttributeArgument class using the specified name and value.
Public Properties
Name Read-write

Gets or sets the name of the attribute.
Value Read-write

Gets or sets the value for the attribute argument.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.CodeDom.CodeAttributeArgument Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the CodeAttributeArgument class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public CodeAttributeArgument();

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the CodeAttributeArgument class using the specified value.
C# Syntax:
public CodeAttributeArgument(
   CodeExpression value
);
Parameters:

value

A CodeExpression that represents the value of the argument.

See also:
CodeExpression

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the CodeAttributeArgument class using the specified name and value.
C# Syntax:
public CodeAttributeArgument(
   string name,
   CodeExpression value
);
Parameters:

name

The name of the attribute property the argument applies to.

value

A CodeExpression that represents the value of the argument.

See also:
CodeExpression

Return to top


Property: Name (read-write)
Summary
Gets or sets the name of the attribute.
C# Syntax:
public string Name {get; set;}

Return to top


Property: Value (read-write)
Summary
Gets or sets the value for the attribute argument.
C# Syntax:
public CodeExpression Value {get; set;}
See also:
CodeExpression

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~CodeAttributeArgument();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.