Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / Visual Basic

Active Directory Object Navigator

Rate me:
Please Sign up or sign in to vote.
4.67/5 (21 votes)
25 Apr 20054 min read 264.4K   6.4K   108  
An article describing how to connect to an Active Directory database.
using System;
using System.Collections;

namespace BVA.ActiveDirectory.Navigator.Objects
{
	/// <summary>
	/// Collection of groups.
	/// </summary>
	public class GroupCollection : CollectionBase 
	{
		/// <summary>
		/// This property indicates if the collection is fixed.
		/// </summary>
		public virtual bool IsFixed 
		{
			get 
			{
				return false;
			}
		}
    
		/// <summary>
		/// This property indicates if the collection is readonly.
		/// </summary>
		public virtual bool IsReadOnly 
		{
			get 
			{
				return false;
			}
		}
    
		/// <summary>
		/// Enumerator for this collection.
		/// </summary>
		public virtual Group this[int index] 
		{
			get 
			{
				if (!((Group)this.List[index]).IsLoaded)
				{
					((Group)this.List[index]).Load();
				}
				return (Group) this.List[index];
			}
			set 
			{
				this.List[index] = value;
			}
		}

		/// <summary>
		/// Enumerator for this collection. This enumerator gets an item through its name.
		/// </summary>
		public virtual Group this[string name] 
		{
			get 
			{
				int index = -1;
				for (int i=0; i<this.List.Count; i++)
				{
					if (((Group)this.List[i]).Name==name)
					{
						index = i;
					}
				}
				if (index==-1){throw new NullReferenceException ("The Group " + name + " was not found.");}
				if (!((Group)this.List[index]).IsLoaded)
				{
					((Group)this.List[index]).Load();
				}
				return (Group) this.List[index];
			}
			set 
			{
				int index = -1;
				for (int i=0; i<this.List.Count; i++)
				{
					if (((Group)this.List[i]).Name==name)
					{
						index = i;
					}
				}
				if (index==-1){throw new NullReferenceException ("The Group " + name + " was not found.");}
				this.List[index] = value;
			}
		}
    
		/// <summary>
		/// Returns the index (position) of an item in the collection.
		/// </summary>
		/// <param name="item">Item to be searched.</param>
		/// <returns>Returns the index(position) of the item.</returns>
		public virtual int IndexOf(Group item) 
		{
			return this.List.IndexOf(item);
		}
    
		/// <summary>
		/// This method appends an item to the collection.
		/// </summary>
		/// <param name="item">Item to be appended to the collection.</param>
		/// <returns>Returns an integer indicating if the item was added.</returns>
		public virtual int Add(Group item) 
		{
			return this.List.Add(item);
		}
    
		/// <summary>
		/// Removes an item from the collection.
		/// </summary>
		/// <param name="item">Item to be removed from the collection.</param>
		public virtual void Remove(Group item) 
		{
			this.List.Remove(item);
		}
    
		/// <summary>
		/// Copies an array to another.
		/// </summary>
		/// <param name="array">Array to be copied.</param>
		/// <param name="index">Index to begin the copy.</param>
		public virtual void CopyTo(Array array, int index) 
		{
			this.List.CopyTo(array, index);
		}
    
		/// <summary>
		/// This methoid adds one collection to this collection.
		/// </summary>
		/// <param name="collection">Collection to be added.</param>
		public virtual void AddRange(GroupCollection collection) 
		{
			this.InnerList.AddRange(collection);
		}
    
		/// <summary>
		/// Adds one collection to this collection.
		/// </summary>
		/// <param name="collection">Collection to be added.</param>
		public virtual void AddRange(Group[] collection) 
		{
			this.InnerList.AddRange(collection);
		}
    
		/// <summary>
		/// This method tells if the collection contains the item.
		/// </summary>
		/// <param name="item">Item to be tested.</param>
		/// <returns>Returns true if the collection contains the item.</returns>
		public virtual bool Contains(Group item) 
		{
			return this.List.Contains(item);
		}
    
		/// <summary>
		/// Inserts an item in the collection.
		/// </summary>
		/// <param name="index">Position to be inserted.</param>
		/// <param name="item">Item to be inserted.</param>
		public virtual void Insert(int index, Group item) 
		{
			this.List.Insert(index, item);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
Bernardo Heynemann is a senior developer at ThoughtWorks UK in London. He is really into Visual Studio 2008, LINQ and ASP.Net MVC. He's also chairman of Stormwind Project (http://www.stormwindproject.org). He can be found at his blog at http://blogs.manicprogrammer.com/heynemann.

Comments and Discussions