Export (0) Print
Expand All

CodeAttributeDeclarationCollection Class

Represents a collection of CodeAttributeDeclaration objects.

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

[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class CodeAttributeDeclarationCollection : CollectionBase
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class CodeAttributeDeclarationCollection extends CollectionBase
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class CodeAttributeDeclarationCollection extends CollectionBase
Not applicable.

The CodeAttributeDeclarationCollection class provides a simple collection object that can be used to store a set of CodeAttributeDeclaration objects.

// Creates an empty CodeAttributeDeclarationCollection.
CodeAttributeDeclarationCollection collection = new CodeAttributeDeclarationCollection();

// Adds a CodeAttributeDeclaration to the collection.
collection.Add( new CodeAttributeDeclaration("DescriptionAttribute",  new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))) );

// Adds an array of CodeAttributeDeclaration objects 
// to the collection.
CodeAttributeDeclaration[] declarations = { new CodeAttributeDeclaration(), new CodeAttributeDeclaration() };
collection.AddRange( declarations );

// Adds a collection of CodeAttributeDeclaration objects 
// to the collection.
CodeAttributeDeclarationCollection declarationsCollection = new CodeAttributeDeclarationCollection();
declarationsCollection.Add( new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))) );
declarationsCollection.Add( new CodeAttributeDeclaration("BrowsableAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(true))) );
collection.AddRange( declarationsCollection );

// Tests for the presence of a CodeAttributeDeclaration in 
// the collection, and retrieves its index if it is found.
CodeAttributeDeclaration testdeclaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")) );
int itemIndex = -1;
if( collection.Contains( testdeclaration ) )
    itemIndex = collection.IndexOf( testdeclaration );

// Copies the contents of the collection, beginning at index 0,
// to the specified CodeAttributeDeclaration array.
// 'declarations' is a CodeAttributeDeclaration array.
collection.CopyTo( declarations, 0 );

// Retrieves the count of the items in the collection.
int collectionCount = collection.Count;

// Inserts a CodeAttributeDeclaration at index 0 of the collection.
collection.Insert( 0, new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))) );

// Removes the specified CodeAttributeDeclaration from 
// the collection.
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")) );
collection.Remove( declaration );

// Removes the CodeAttributeDeclaration at index 0.
collection.RemoveAt(0);

// Creates an empty CodeAttributeDeclarationCollection.
CodeAttributeDeclarationCollection collection =
    new CodeAttributeDeclarationCollection();

// Adds a CodeAttributeDeclaration to the collection.
collection.Add(new CodeAttributeDeclaration("DescriptionAttribute",
    new CodeAttributeArgument[] { new CodeAttributeArgument(
    new CodePrimitiveExpression("Test Description")) }));

// Adds an array of CodeAttributeDeclaration objects 
// to the collection.
CodeAttributeDeclaration declarations[] =  {
    new CodeAttributeDeclaration(),
    new CodeAttributeDeclaration() };
collection.AddRange(declarations);

// Adds a collection of CodeAttributeDeclaration objects 
// to the collection.
CodeAttributeDeclarationCollection declarationsCollection =
    new CodeAttributeDeclarationCollection();
declarationsCollection.Add(new CodeAttributeDeclaration(
    "DescriptionAttribute", new CodeAttributeArgument[] {
    new CodeAttributeArgument(new CodePrimitiveExpression(
    "Test Description")) }));
declarationsCollection.Add(new CodeAttributeDeclaration(
    "BrowsableAttribute", new CodeAttributeArgument[] {
    new CodeAttributeArgument(new CodePrimitiveExpression(
    (System.Boolean)true)) }));
collection.AddRange(declarationsCollection);

// Tests for the presence of a CodeAttributeDeclaration in 
// the collection, and retrieves its index if it is found.
CodeAttributeDeclaration testdeclaration =
    new CodeAttributeDeclaration("DescriptionAttribute",
    new CodeAttributeArgument[] { new CodeAttributeArgument(
    new CodePrimitiveExpression("Test Description")) });
int itemIndex = -1;
if (collection.Contains(testdeclaration)) {
    itemIndex = collection.IndexOf(testdeclaration);
}
// Copies the contents of the collection, beginning at index 0,
// to the specified CodeAttributeDeclaration array.
// 'declarations' is a CodeAttributeDeclaration array.
collection.CopyTo(declarations, 0);

// Retrieves the count of the items in the collection.
int collectionCount = collection.get_Count();

// Inserts a CodeAttributeDeclaration at index 0 of the collection.
collection.Insert(0, new CodeAttributeDeclaration(
    "DescriptionAttribute",new CodeAttributeArgument[] {
    new CodeAttributeArgument(new CodePrimitiveExpression(
    "Test Description")) }));

// Removes the specified CodeAttributeDeclaration from 
// the collection.
CodeAttributeDeclaration declaration =
    new CodeAttributeDeclaration("DescriptionAttribute",
    new CodeAttributeArgument[] { new CodeAttributeArgument(
    new CodePrimitiveExpression("Test Description")) });
collection.Remove(declaration);

// Removes the CodeAttributeDeclaration at index 0.
collection.RemoveAt(0);

System.Object
   System.Collections.CollectionBase
    System.CodeDom.CodeAttributeDeclarationCollection

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