CodeDirectiveCollection Class

Represents a collection of CodeDirective objects.

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

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

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

The following code example shows the use of the members of the CodeDirectiveCollection class.

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

// Adds a CodeDirective to the collection.
collection.Add(new CodeRegionDirective(CodeRegionMode.Start, "Region1"));

// Adds an array of CodeDirective objects to the collection.
CodeDirective[] directives = { 
    new CodeRegionDirective(CodeRegionMode.Start,"Region1"), 
    new CodeRegionDirective(CodeRegionMode.End,"Region1") };

// Adds a collection of CodeDirective objects to the collection.
CodeDirectiveCollection directivesCollection = new CodeDirectiveCollection();
directivesCollection.Add(new CodeRegionDirective(CodeRegionMode.Start, "Region2"));
directivesCollection.Add(new CodeRegionDirective(CodeRegionMode.End, "Region2"));

// Tests for the presence of a CodeDirective in the 
// collection, and retrieves its index if it is found.
CodeDirective testDirective = new CodeRegionDirective(CodeRegionMode.Start, "Region1");
int itemIndex = -1;
if (collection.Contains(testDirective))
    itemIndex = collection.IndexOf(testDirective);

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

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

// Inserts a CodeDirective at index 0 of the collection.
collection.Insert(0, new CodeRegionDirective(CodeRegionMode.Start, "Region1"));

// Removes the specified CodeDirective from the collection.
CodeDirective directive = new CodeRegionDirective(CodeRegionMode.Start, "Region1");

// Removes the CodeDirective at index 0.


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