CodeAttributeDeclaration Class
Collapse the table of content
Expand the table of content

CodeAttributeDeclaration Class


Represents an attribute declaration.

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


public class CodeAttributeDeclaration


Initializes a new instance of the CodeAttributeDeclaration class.


Initializes a new instance of the CodeAttributeDeclaration class using the specified code type reference.

System_CAPS_pubmethodCodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[])

Initializes a new instance of the CodeAttributeDeclaration class using the specified code type reference and arguments.


Initializes a new instance of the CodeAttributeDeclaration class using the specified name.

System_CAPS_pubmethodCodeAttributeDeclaration(String, CodeAttributeArgument[])

Initializes a new instance of the CodeAttributeDeclaration class using the specified name and arguments.


Gets the arguments for the attribute.


Gets the code type reference for the code attribute declaration.


Gets or sets the name of the attribute being declared.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

A CodeAttributeDeclaration can be used to represent an expression that declares an attribute. The attribute name and the arguments for the attribute are stored as properties of the object. A CodeAttributeArgument can be used to represent each argument for the attribute.

The following code example creates a CodeAttributeDeclaration that declares a CLSCompliantAttribute with an argument of false:

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// This is the class that will be serialized.
public class Group
   // This is the attribute that will be overridden.
   public string GroupName;
   public int GroupNumber;

public class Run
   public static void Main()
      Run test = new Run();
   // Return an XmlSerializer used for overriding. 
   public XmlSerializer CreateOverrider()
      // Create the XmlAttributeOverrides and XmlAttributes objects.
      XmlAttributeOverrides xOver = new XmlAttributeOverrides();
      XmlAttributes xAttrs = new XmlAttributes();

      /* Create an overriding XmlAttributeAttribute set it to 
      the XmlAttribute property of the XmlAttributes object.*/
      XmlAttributeAttribute xAttribute = new XmlAttributeAttribute("SplinterName");
      xAttrs.XmlAttribute = xAttribute;

      // Add to the XmlAttributeOverrides. Specify the member name.
      xOver.Add(typeof(Group), "GroupName", xAttrs);

      // Create the XmlSerializer and return it.
      return new XmlSerializer(typeof(Group), xOver);

   public void SerializeObject(string filename)
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrider();
      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      /* Set the Name property, which will be generated 
      as an XML attribute. */
      myGroup.GroupName = ".NET";
      myGroup.GroupNumber = 1;
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);

   public void DeserializeObject(string filename)
      XmlSerializer mySerializer = CreateOverrider();
      FileStream fs = new FileStream(filename, FileMode.Open);
      Group myGroup = (Group) 


.NET Framework
Available since 1.1

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

Return to top
© 2015 Microsoft