Export (0) Print
Expand All

CodeAttributeDeclarationCollection Class

Represents a collection of CodeAttributeDeclaration objects.

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

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

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeAttributeDeclarationCollection
   Inherits CollectionBase
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeAttributeDeclarationCollection : CollectionBase
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeAttributeDeclarationCollection : public
   CollectionBase
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeAttributeDeclarationCollection extends
   CollectionBase

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.

Remarks

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

Example

[Visual Basic] 
' Creates an empty CodeAttributeDeclarationCollection.
Dim collection As 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.
Dim declarations As CodeAttributeDeclaration() = {New CodeAttributeDeclaration(), New CodeAttributeDeclaration()}
collection.AddRange(declarations)

' Adds a collection of CodeAttributeDeclaration objects to 
' the collection.
Dim declarationsCollection As 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.
Dim testdeclaration As New CodeAttributeDeclaration("DescriptionAttribute", New CodeAttributeArgument(New CodePrimitiveExpression("Test Description")))
Dim itemIndex As Integer = -1
If collection.Contains(testdeclaration) Then
    itemIndex = collection.IndexOf(testdeclaration)
End If

' 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.
Dim collectionCount As Integer = 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.
Dim declaration As New CodeAttributeDeclaration("DescriptionAttribute", New CodeAttributeArgument(New CodePrimitiveExpression("Test Description")))
collection.Remove(declaration)

' Removes the CodeAttributeDeclaration at index 0.
collection.RemoveAt(0)

[C#] 
// 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);

[C++] 
// Creates an empty CodeAttributeDeclarationCollection.
CodeAttributeDeclarationCollection* collection = new CodeAttributeDeclarationCollection();

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

// 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();
CodeAttributeArgument* temp1[] = {new CodeAttributeArgument(new CodePrimitiveExpression(S"Test Description"))};
declarationsCollection->Add( new CodeAttributeDeclaration(S"DescriptionAttribute",temp1) );
CodeAttributeArgument* temp2[] = {new CodeAttributeArgument(new CodePrimitiveExpression(__box(true)))};
declarationsCollection->Add( new CodeAttributeDeclaration(S"BrowsableAttribute", temp2) );
collection->AddRange( declarationsCollection );

// Tests for the presence of a CodeAttributeDeclaration in 
// the collection, and retrieves its index if it is found.
CodeAttributeArgument* temp3[] = {new CodeAttributeArgument(new CodePrimitiveExpression(S"Test Description"))};
CodeAttributeDeclaration* testdeclaration = new CodeAttributeDeclaration(S"DescriptionAttribute", temp3);
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.
CodeAttributeArgument* temp4[] = {new CodeAttributeArgument(new CodePrimitiveExpression(S"Test Description"))};
collection->Insert( 0, new CodeAttributeDeclaration(S"DescriptionAttribute", temp4) );

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

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

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

Requirements

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

CodeAttributeDeclarationCollection Members | System.CodeDom Namespace | CodeAttributeDeclaration

Show:
© 2014 Microsoft