brain frozen on enumerator

  • Thread starter Thread starter Stephanie Stowe
  • Start date Start date
S

Stephanie Stowe

Hi. I am trying to understand the weird System.DirectoryServices object
model. I have a DirectoryEntry object. I want to enumerate through the
PropertyCollection. So I looked at GetEnumerator. Lovely. My memory cannot
dredge up how to use an enumerator. I do not understand the documentation,
whcih does not contain little code snippets of examples like MSDN Oct 2001
for older technologies did. Can someone give me an enumerator basics 101
reference? I cannot find one.

DirectoryEntry test = new DirectoryEntry("IIS://" + serverName +
"/w3svc/1/root", serverName + "\\administrator", password,
AuthenticationTypes.Secure);
DirectoryEntry schema = test.SchemaEntry;

I want to loop through schema and look at all the property names and values.

Thanks
 
An enumerator will implement IEnumerator. An enumerator basically iterates
some list and enables you to get the items in order.

When you get an enumerator it will be primed and ready to get the first item
in the list. You index each item with the MoveNext command so you can do...

while(myEnumerator.MoveNext())
{
//do something with myEnumerator.Current here
}
//we get here when the list is exhausted

Probably the easiest way to use an enumerator is in conjunction with the
foreach statement so you might do something like:

foreach(string s in test.SchemaEntry.Properties.PropertyNames)
Console.WriteLine(s);

This will dump the names of the properties in the directory entry


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top