<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Programming bits</title><link>http://blogs.vbcity.com/hotdog/category/31.aspx</link><description>Just some general memos on what to do or not to do in .Net</description><managingEditor>Robert Verpalen</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Robert Verpalen</dc:creator><title>ActiveDirectory and C#</title><link>http://blogs.vbcity.com/hotdog/archive/2007/07/05/8489.aspx</link><pubDate>Thu, 05 Jul 2007 08:40:00 GMT</pubDate><guid>http://blogs.vbcity.com/hotdog/archive/2007/07/05/8489.aspx</guid><wfw:comment>http://blogs.vbcity.com/hotdog/comments/8489.aspx</wfw:comment><comments>http://blogs.vbcity.com/hotdog/archive/2007/07/05/8489.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.vbcity.com/hotdog/comments/commentRss/8489.aspx</wfw:commentRss><trackback:ping>http://blogs.vbcity.com/hotdog/services/trackbacks/8489.aspx</trackback:ping><description>&lt;P&gt;the System.DirectoryServices namespace from .net allready contains a lot of build&amp;nbsp;in functionality for use with Active Directory. However some default task have to coded manually still. Of course that meant writing some support tools which I've been happilly using for some time now :)&lt;BR&gt;The code posted here are the base classes used for those tools. At a later time if anyone is interested I'll include the tools project too (simple LDAP browser, user form that can lock/unlock, set pw and mail forwardings)&lt;/P&gt;
&lt;P&gt;The code is wrapped around the System.DirectoryServices objects and thus need a reference to that (default .net) namespace. The static ActiveDirectory class contains methods to quickly search entries. The ActiveDirectoryEntry class is a wrapper around the .net DirectoryEntry class which encapsulates functions to quickly access properties. ADFilter makes creating queries easier and UserInfo is a class that uses the other classes to quickly get and set user info.&lt;/P&gt;
&lt;P&gt;Example usage:&lt;/P&gt;&lt;!-- --Start of code block
--&gt;
&lt;DIV style="BORDER-RIGHT: #000080 1px solid; BORDER-TOP: #000080 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #000080 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #000080 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 9pt; BORDER-BOTTOM: #000080 1px solid; FONT-FAMILY: 'Microsoft Sans Serif'"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 10pt" onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy&lt;/A&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;
&lt;DIV style="OVERFLOW: auto; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;FONT color=#008000&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;//get a single entry&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;BR&gt;ActiveDirectoryEntry&lt;/FONT&gt; d = &lt;FONT color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetEntry(&lt;FONT color=#a31515&gt;"srv*"&lt;/FONT&gt;, &lt;FONT color=#a31515&gt;"computer"&lt;/FONT&gt;);&lt;FONT color=#2b91af&gt;&lt;BR&gt;Console&lt;/FONT&gt;.WriteLine(d[&lt;FONT color=#a31515&gt;"whenCreated"&lt;/FONT&gt;]);&lt;/DIV&gt;&lt;FONT color=#008000&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;//The default activedirectory queries can be used to find entries&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;//list all computers:&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;foreach&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetEntries(&lt;FONT color=#a31515&gt;"objectClass=computer"&lt;/FONT&gt;))&lt;BR&gt;{&lt;FONT color=#2b91af&gt; 
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Console&lt;/FONT&gt;.WriteLine(de.Name);&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#008000&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;//list all users whose password was changed in the last 2 months&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;string&lt;/FONT&gt; date = &lt;FONT color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.FormatDateTime( &lt;FONT color=#2b91af&gt;DateTime&lt;/FONT&gt;.Today.AddMonths(-2));&lt;FONT color=#0000ff&gt;&lt;BR&gt;foreach&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetEntries(&lt;FONT color=#a31515&gt;"(&amp;amp;(objectClass=user)(whenCreated&amp;gt;="&lt;/FONT&gt;+date+&lt;FONT color=#a31515&gt;"))"&lt;/FONT&gt;))&lt;BR&gt;{&lt;FONT color=#2b91af&gt; 
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Console&lt;/FONT&gt;.WriteLine(&lt;FONT color=#a31515&gt;"{0}, created: {1}"&lt;/FONT&gt;, de.Name, de[&lt;FONT color=#a31515&gt;"whenCreated"&lt;/FONT&gt;]);&lt;/DIV&gt;}&lt;BR&gt;&lt;/DIV&gt;&lt;FONT color=#008000&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;//Another method is to use the ADFilter object, which makes writing those nasty queries somewhat easer&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;//Doing the same as above:&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;BR&gt;ADFilter&lt;/FONT&gt; filter = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;BR&gt;filter.objectClass = &lt;FONT color=#a31515&gt;"user"&lt;/FONT&gt;;&lt;BR&gt;filter.Add(&lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ADCriterium&lt;/FONT&gt;(&lt;FONT color=#a31515&gt;"whenCreated"&lt;/FONT&gt;, &lt;FONT color=#2b91af&gt;Operator&lt;/FONT&gt;.Equals | &lt;FONT color=#2b91af&gt;Operator&lt;/FONT&gt;.GreaterThan,&lt;FONT color=#2b91af&gt;DateTime&lt;/FONT&gt;.Today.AddMonths(-2)));&lt;FONT color=#2b91af&gt;&lt;BR&gt;Console&lt;/FONT&gt;.WriteLine(filter);&lt;FONT color=#0000ff&gt;&lt;BR&gt;foreach&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetEntries(filter))&lt;BR&gt;{&lt;FONT color=#2b91af&gt; 
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Console&lt;/FONT&gt;.WriteLine(&lt;FONT color=#a31515&gt;"{0}, created: {1}"&lt;/FONT&gt;, de.Name, de[&lt;FONT color=#a31515&gt;"whenCreated"&lt;/FONT&gt;]);&lt;/DIV&gt;}&lt;/DIV&gt;&lt;FONT color=#008000&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;//for a small query as above the filter isn't so important, but imagine the more complicated&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;//scenario of also wanting to search for&amp;nbsp;&amp;nbsp;at names beginning with w or a badlogincount of 0&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;BR&gt;ADFilter&lt;/FONT&gt; subquery = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;BR&gt;subquery[&lt;FONT color=#a31515&gt;"cn"&lt;/FONT&gt;] = &lt;FONT color=#a31515&gt;"w*"&lt;/FONT&gt;;&lt;BR&gt;subquery[&lt;FONT color=#a31515&gt;"badPwdCount"&lt;/FONT&gt;] = 0;&lt;BR&gt;filter.Add(subquery);&lt;FONT color=#008000&gt;&lt;BR&gt;//this produces the following filter:&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(&amp;amp;(objectClass=user)(whenCreated&amp;gt;=070505000000Z)(&amp;amp;(cn=w*)(badPwdCount=0)))&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;BR&gt;Console&lt;/FONT&gt;.WriteLine(filter);&lt;FONT color=#0000ff&gt;&lt;BR&gt;foreach&lt;/FONT&gt; (&lt;FONT color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetEntries(filter))&lt;BR&gt;{&lt;FONT color=#2b91af&gt; 
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;Console&lt;/FONT&gt;.WriteLine(&lt;FONT color=#a31515&gt;"{0}, created: {1}"&lt;/FONT&gt;, de.Name, de[&lt;FONT color=#a31515&gt;"whenCreated"&lt;/FONT&gt;]);&lt;/DIV&gt;}&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- 
End of code block----&gt;
&lt;P&gt;Example usage UserInfo class:&lt;/P&gt;&lt;!-- --Start of code block
--&gt;
&lt;DIV style="BORDER-RIGHT: #000080 1px solid; BORDER-TOP: #000080 1px solid; MARGIN-LEFT: 10pt; BORDER-LEFT: #000080 1px solid; MARGIN-RIGHT: 2pt; BORDER-BOTTOM: #000080 1px solid"&gt;
&lt;DIV style="FONT-SIZE: 9pt; BORDER-BOTTOM: #000080 1px solid; FONT-FAMILY: 'Microsoft Sans Serif'"&gt;&lt;B&gt;Code &lt;/B&gt;&lt;A style="MARGIN-LEFT: 10pt; MARGIN-RIGHT: 10pt" onclick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');" href="javascript:"&gt;Copy&lt;/A&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;
&lt;DIV style="OVERFLOW: auto; BACKGROUND-COLOR: #dcdcdc"&gt;&lt;FONT color=#008000&gt;
&lt;DIV style="MARGIN-LEFT: 60pt"&gt;//getting the current user can be done with the GetCurrentUser function&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;BR&gt;UserInfo&lt;/FONT&gt; ui = &lt;FONT color=#2b91af&gt;UserInfo&lt;/FONT&gt;.GetCurrentUser();&lt;FONT color=#0000ff&gt;&lt;BR&gt;string&lt;/FONT&gt; surname = ui.SurName;&lt;BR&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;//some other user (when using wildcard searches, the first found entry is used)&lt;/FONT&gt;&lt;BR&gt;ui = &lt;FONT color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT color=#2b91af&gt;UserInfo&lt;/FONT&gt;(&lt;FONT color=#a31515&gt;"Hotd*"&lt;/FONT&gt;);&lt;FONT color=#008000&gt;&lt;BR&gt;//NB: if the user is not found, calling properties will throw an exception&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;// which informs that no active directory entry exists&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;BR&gt;// You can check if a valid entry was found by checking the HasActiveDirectoryEntry property&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;if&lt;/FONT&gt; (!ui.HasActiveDirectoryEntry) &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt;;&lt;FONT color=#0000ff&gt;&lt;BR&gt;if&lt;/FONT&gt; (ui.IsMailForwarded)&lt;BR&gt;{&lt;FONT color=#0000ff&gt; 
&lt;DIV style="MARGIN-LEFT: 20pt"&gt;string&lt;/FONT&gt; mail = ui.MailForwardedTo.FullName;&lt;/DIV&gt;}&lt;FONT color=#008000&gt;&lt;BR&gt;//other functions included, for example password changing&lt;/FONT&gt;&lt;BR&gt;ui.SetPassword(&lt;FONT color=#a31515&gt;"NewPassword"&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;);&lt;FONT color=#0000ff&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;!-- 
End of code block----&gt;
&lt;P&gt;The classes:&lt;/P&gt;

&lt;!-- --Start of code block
--&gt;&lt;DIV Style=" Border='1px #000080 solid'; Margin-Left=10pt; Margin-Right=2pt;" OnKeyDown="var k =event.keyCode,i=-1,ch=this.firstChild;if(k==32){i=ch.sel;if(++i==ch.selcount)i=0;}else i = k - 49;if(i&gt;=0 &amp;&amp; i&lt;ch.selcount){ch.sel=i;ch.click();}"&gt;&lt;DIV Style=" Font-Size=9pt; Font-Family='Microsoft Sans Serif'; Border-Bottom='1px #000080 solid';" OnClick="var i=this.sel,j,ch,count = this.selcount;if(i==this.selold)return;this.selold=i;for(j=0;j&lt;count;j++){ch=this.childNodes[2+j];ch.childNodes[0].checked=j==i;ch.style.fontWeight = j==i ? 'bolder' : 'normal';}ch=parentNode.childNodes[1];var sh=new Array('none','');j=i==0?0:1;ch.style.display=sh[j];ch.nextSibling.style.display=sh[1-j];var h =ch.offsetHeight;ch.style.height=i==1?'300pt':null;if(i==1&amp;&amp; ch.offsetHeight&gt;h)ch.style.height=h;" sel=1 selold=1 selcount=3&gt;&lt;b&gt;  Code &lt;/b&gt;&lt;a href="javascript:" Style=" Margin-Left=10pt; Margin-Right=10pt;" OnClick="window.clipboardData.setData('Text',this.parentNode.parentNode.childNodes[1].innerText);alert('Code copied to clipboard');"&gt;Copy&lt;/a&gt;&lt;SPAN Style=" Margin-Left=5pt; Margin-Right=5pt; Cursor='hand';" OnClick="parentNode.sel=0"&gt;&lt;Input Type="Radio" Style="" OnClick="this.blur();"&gt;Hide&lt;/SPAN&gt;&lt;SPAN Style=" Font-Weight=bolder; Margin-Left=5pt; Margin-Right=5pt; Cursor='hand';" OnClick="parentNode.sel=1"&gt;&lt;Input Type="Radio" Style="" OnClick="this.blur();" Checked=True&gt;Scroll&lt;/SPAN&gt;&lt;SPAN Style=" Margin-Left=5pt; Margin-Right=5pt; Cursor='hand';" OnClick="parentNode.sel=2"&gt;&lt;Input Type="Radio" Style="" OnClick="this.blur();"&gt;Full&lt;/SPAN&gt;&lt;!-- CodeBlock by R.Verpalen 2005 : http://blogs.vbcity.com/hotdog/archive/2005/12/30/5759.aspx--&gt;&lt;/DIV&gt;&lt;DIV Style=" BackGround-Color=#dcdcdc; overflow='auto'; Height=300pt;"&gt;&lt;FONT Color=#008000&gt;//#define Framework30 //uncomment this line if you want to include framework 3.0 functions such as Linq&lt;br&gt;&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Collections.Generic;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Text;&lt;FONT Color=#008000&gt;&lt;br&gt;//needs a reference to System.DirectoryServices&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.DirectoryServices;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; ad = System.DirectoryServices.ActiveDirectory;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Runtime.InteropServices;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; System.Collections.Specialized;&lt;FONT Color=#0000ff&gt;&lt;br&gt;#if&lt;/FONT&gt; Framework30&lt;FONT Color=#808080&gt;&lt;br&gt;using System.Linq;&lt;br&gt;using System.Linq.Expressions;&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;#endif&lt;br&gt;&lt;br&gt;namespace&lt;/FONT&gt; AD&lt;br&gt;{&lt;FONT Color=#808080&gt;&lt;div style="margin-left:20pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Base class for all returned directory entries&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DirectoryEntry&lt;/FONT&gt; Entry;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ActiveDirectoryEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Path)&lt;div style="margin-left:20pt"&gt;: &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DirectoryEntry&lt;/FONT&gt;(Path))&lt;/div&gt;{&lt;br&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;internal&lt;/FONT&gt; ActiveDirectoryEntry(&lt;FONT Color=#2b91af&gt;DirectoryEntry&lt;/FONT&gt; Entry)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (Entry == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;throw&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ArgumentNullException&lt;/FONT&gt;();&lt;FONT Color=#0000ff&gt;&lt;/div&gt;this&lt;/FONT&gt;.Entry = Entry;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetEntry(&lt;FONT Color=#2b91af&gt;DirectoryEntry&lt;/FONT&gt; Entry)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (Entry == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;(Entry);&lt;/div&gt;}&lt;FONT Color=#008000&gt;&lt;br&gt;/*&lt;br&gt;public static implicit operator ActiveDirectoryEntry(DirectoryEntry de)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (de == null) return null;&lt;br&gt;return new ActiveDirectoryEntry(de);&lt;/div&gt;}*/&lt;/FONT&gt;&lt;FONT Color=#008000&gt;&lt;br&gt;/*&lt;br&gt;public static implicit operator DirectoryEntry(ActiveDirectoryEntry de)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return de.Entry;&lt;/div&gt;}*/&lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Path&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Entry.Path; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; Invoke(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; methodName, &lt;FONT Color=#0000ff&gt;params&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt;[] args)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Entry.Invoke(methodName, args);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; InvokeGet(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; methodName)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; Entry.InvokeGet(methodName);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; InvokeSet(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; methodName, &lt;FONT Color=#0000ff&gt;params&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt;[] args)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Entry.InvokeSet(methodName, args);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; CommitChanges()&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Entry.CommitChanges();&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; RefreshCache()&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Entry.RefreshCache();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:40pt"&gt;ActiveDirectoryEntry&lt;/FONT&gt; parent;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; Parent&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (parent == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;parent = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;(Entry.Parent);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; parent;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;const&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; memberof = &lt;FONT Color=#a31515&gt;&amp;quotmemberof&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;const&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; members = &lt;FONT Color=#a31515&gt;&amp;quotmember&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt EnumerateMemberOf()&lt;br&gt;{&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; Properties[memberof])&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; GetEntry(s);&lt;/div&gt;}&lt;FONT Color=#2b91af&gt;&lt;br&gt;ActiveDirectoryEntry&lt;/FONT&gt; e = GetPrimaryGroup();&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (e != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; e;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; IsMemberOf(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Group)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;object&lt;/FONT&gt; o = &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[memberof];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (o == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;FONT Color=#2b91af&gt;&lt;br&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt;&amp;gt owners = o &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ? &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;[] { (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;)o } : (&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt;[])o;&lt;br&gt;Group = &lt;FONT Color=#a31515&gt;&amp;quotCN=&amp;quot&lt;/FONT&gt; + Group;&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; owners)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (s.Contains(Group)) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; IsMemberOf(&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; group)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ad &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; EnumerateMemberOf())&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (ad.Equals(group)) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AccessType&lt;/FONT&gt; GetAccessType(&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; group)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt list = GetMemberOf();&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ad &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; list)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (ad.Equals(group)) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AccessType&lt;/FONT&gt;.Direct;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ad &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; list)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;AccessType&lt;/FONT&gt; at = ad.GetAccessType(group);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (at != &lt;FONT Color=#2b91af&gt;AccessType&lt;/FONT&gt;.None)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AccessType&lt;/FONT&gt;.Nested;&lt;/div&gt;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AccessType&lt;/FONT&gt;.None;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Prefix&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; Path.Remove(Path.IndexOf(&lt;FONT Color=#a31515&gt;&amp;quot//&amp;quot&lt;/FONT&gt;) + 2);&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:40pt"&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;string&lt;/FONT&gt; path = Prefix + Clean(s);&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;(path);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;string&lt;/FONT&gt; Clean(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (s.IndexOf(&lt;FONT Color=#a31515&gt;'/'&lt;/FONT&gt;) &amp;gt= 0)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;s = s.Replace(&lt;FONT Color=#a31515&gt;&amp;quot/&amp;quot&lt;/FONT&gt;, &lt;FONT Color=#a31515&gt;@&amp;quot\/&amp;quot&lt;/FONT&gt;);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; s;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; IsTop&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; Entry.Parent.SchemaClassName == &lt;FONT Color=#a31515&gt;&amp;quotdomainDNS&amp;quot&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; IsEndpoint&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;switch&lt;/FONT&gt; (Class)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;case&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.organizationalUnit:&lt;FONT Color=#0000ff&gt;&lt;br&gt;case&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.container:&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;default&lt;/FONT&gt;:&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; SchemaClassName&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Entry.SchemaClassName; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt; Class&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;try&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;)&lt;FONT Color=#2b91af&gt;Enum&lt;/FONT&gt;.Parse(&lt;FONT Color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;), Entry.SchemaClassName);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;catch&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.any;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetMemberOf()&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt res = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt();&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; EnumerateMemberOf())&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;res.Add(de);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; res;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;PropertyValueCollection&lt;/FONT&gt; MemberOf&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Properties[memberof]; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;PropertyValueCollection&lt;/FONT&gt; Members&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Properties[members]; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetMembers()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; Members)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; GetEntry(s);&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:60pt"&gt;System.Security.Principal.&lt;FONT Color=#2b91af&gt;SecurityIdentifier&lt;/FONT&gt; sid = GetSID();&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (sid != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;string&lt;/FONT&gt; s = sid.ToString();&lt;FONT Color=#0000ff&gt;&lt;br&gt;int&lt;/FONT&gt; i = s.LastIndexOf(&lt;FONT Color=#a31515&gt;'-'&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (i != -1)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;s = s.Substring(++i);&lt;FONT Color=#008000&gt;&lt;br&gt;//byte[] b = GetSIDArray();&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/FONT&gt;&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:100pt"&gt;ADFilter&lt;/FONT&gt; filter = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotprimarygroupID&amp;quot&lt;/FONT&gt;, s);&lt;br&gt;filter.ObjectClass = &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.user;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:100pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ad &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; filter.GetEntries())&lt;br&gt;{&lt;FONT Color=#008000&gt;&lt;div style="margin-left:20pt"&gt;//if(IsEqual(b,ad.GetSIDArray(),b.Length-4))&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; ad;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:80pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:60pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;bool&lt;/FONT&gt; IsEqual(&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[] b1, &lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[] b2, &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; len)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;for&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt len; i++)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (b1[i] != b2[i]) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt DeepEnumerateMembers()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;.Class == &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.user)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ad &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; GetMembers())&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; m &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; ad.DeepEnumerateMembers())&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; m;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Name&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;object&lt;/FONT&gt; o = &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#a31515&gt;&amp;quotcn&amp;quot&lt;/FONT&gt;];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (o != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; o.ToString();&lt;br&gt;o = &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#a31515&gt;&amp;quotou&amp;quot&lt;/FONT&gt;];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (o != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; o.ToString();&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; Entry.Name;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; System.Security.Principal.&lt;FONT Color=#2b91af&gt;SecurityIdentifier&lt;/FONT&gt; GetSID()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;byte&lt;/FONT&gt;[] b = GetSIDArray();&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (b == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetSID(b);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;byte&lt;/FONT&gt;[] GetSIDArray()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;object&lt;/FONT&gt; o = GetValue(&lt;FONT Color=#a31515&gt;&amp;quotobjectSid&amp;quot&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (o == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;byte&lt;/FONT&gt;[] b = o &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (b == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (o &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Guid&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;b = ((&lt;FONT Color=#2b91af&gt;Guid&lt;/FONT&gt;)o).ToByteArray();&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;throw&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Exception&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotCould not parse SID of type &amp;quot&lt;/FONT&gt; + o.GetType().FullName);&lt;/div&gt;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; b;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; PrimaryGroupID&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; GetValue&amp;lt&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt;&amp;gt(&lt;FONT Color=#a31515&gt;&amp;quotprimarygroupID&amp;quot&lt;/FONT&gt;); }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetPrimaryGroup()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;int&lt;/FONT&gt; pg = PrimaryGroupID;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (pg == 0) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;br&gt;System.Security.Principal.&lt;FONT Color=#2b91af&gt;SecurityIdentifier&lt;/FONT&gt; sid = GetSID();&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (sid == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;string&lt;/FONT&gt; s = sid.ToString();&lt;FONT Color=#0000ff&gt;&lt;br&gt;int&lt;/FONT&gt; i = s.LastIndexOf(&lt;FONT Color=#a31515&gt;'-'&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (i == -1) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetBySID(s.Substring(0, ++i) + pg.ToString());&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; T GetValue&amp;ltT&amp;gt(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;object&lt;/FONT&gt; o = &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[Property];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (o == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;default&lt;/FONT&gt;(T);&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; (T)o;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; T GetValue&amp;ltT&amp;gt(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property, T Default)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;object&lt;/FONT&gt; o = &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[Property];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (o == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Default;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; (T)o;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; GetValue(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[Property];&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; When true, all changes are automatically comitted when a property is changed&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; AutoSaveChanges = &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; PropertyName]&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryProperty&lt;/FONT&gt;.GetValue(Properties[PropertyName]);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;PropertyValueCollection&lt;/FONT&gt; pv = Properties[PropertyName];&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (pv == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt; == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;throw&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Exception&lt;/FONT&gt;(PropertyName + &lt;FONT Color=#a31515&gt;&amp;quot not found&amp;quot&lt;/FONT&gt;);&lt;/div&gt;}&lt;FONT Color=#2b91af&gt;&lt;br&gt;ActiveDirectoryProperty&lt;/FONT&gt;.SetValue(pv, &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;);&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:80pt"&gt;if&lt;/FONT&gt; (AutoSaveChanges)&lt;div style="margin-left:20pt"&gt;CommitChanges();&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:60pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;PropertyCollection&lt;/FONT&gt; Properties&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Entry.Properties; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; You can get the value directly by using the indexed property (e.g. YourEntry[&amp;quotPropertyName&amp;quot] ), but&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; the &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsee cref=&amp;quotActiveDirectoryProperty&amp;quot/&amp;gt&lt;/FONT&gt;&lt;FONT Color=#008000&gt; encapsulates more functionality around the property.&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltparam name=&amp;quotPropertyName&amp;quot&amp;gt&amp;lt/param&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltreturns&amp;gt&amp;lt/returns&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryProperty&lt;/FONT&gt; GetProperty(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; PropertyName)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryProperty&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;, PropertyName);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryProperty&lt;/FONT&gt;&amp;gt GetProperties()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;PropertyValueCollection&lt;/FONT&gt; pv &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; Properties)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; GetProperty(pv.PropertyName);&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DirectoryEntries&lt;/FONT&gt; Children&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Entry.Children; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; GetHashCode()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; Path.GetHashCode();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; Equals(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; obj)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; obj &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; &amp;amp&amp;amp&lt;div style="margin-left:20pt"&gt;(obj &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;).Path == Path;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ToString()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; Name;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; ImplementsClass(&lt;FONT Color=#0000ff&gt;params&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;[] classes)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; Properties[&lt;FONT Color=#a31515&gt;&amp;quotobjectClass&amp;quot&lt;/FONT&gt;].Value &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt;[])&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;for&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt classes.Length; i++)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (classes[i] == s) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;true&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;false&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;enum&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AccessType&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;None,&lt;br&gt;Direct,&lt;br&gt;Nested&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryProperty&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; Entry;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; PropertyName;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; IsSID;&lt;FONT Color=#2b91af&gt;&lt;br&gt;PropertyValueCollection&lt;/FONT&gt; pv;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ActiveDirectoryProperty(&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; Entry, &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; PropertyName)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.Entry = Entry;&lt;FONT Color=#0000ff&gt;&lt;br&gt;this&lt;/FONT&gt;.PropertyName = PropertyName;&lt;FONT Color=#0000ff&gt;&lt;br&gt;this&lt;/FONT&gt;.pv = Entry.Properties[PropertyName];&lt;br&gt;IsSID = PropertyName == &lt;FONT Color=#a31515&gt;&amp;quotobjectSid&amp;quot&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; AutoSaveChanges&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; Entry.AutoSaveChanges; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt; { Entry.AutoSaveChanges = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; Value&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetValue(pv);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Entry[PropertyName] = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; Exists&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; pv != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; Capacity&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; pv.Capacity;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; HasValue&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; pv != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; &amp;amp&amp;amp pv.Count &amp;gt 0; }&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt;&amp;gt GetValues()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (!HasValue) &lt;FONT Color=#0000ff&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;break&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;for&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt pv.Count; i++)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[i];&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; Index]&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.Convert(pv[Index]);&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; GetValueString()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetValueString(&lt;FONT Color=#2b91af&gt;Environment&lt;/FONT&gt;.NewLine);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; GetValueString(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Seperator)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (!HasValue) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;string&lt;/FONT&gt; res = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;for&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt pv.Count; i++)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (i &amp;gt 0) res += Seperator;&lt;br&gt;res += GetValueString(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[i]);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; res;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;string&lt;/FONT&gt; GetValueString(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; o)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (o &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[])&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (IsSID) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetSID((&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[])o).ToString();&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.ByteArrayToString((&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[])o);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; o.ToString();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ToString()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; PropertyName + &lt;FONT Color=#a31515&gt;&amp;quot: &amp;quot&lt;/FONT&gt; + GetValueString(&lt;FONT Color=#a31515&gt;&amp;quot, &amp;quot&lt;/FONT&gt;);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; GetValue(&lt;FONT Color=#2b91af&gt;PropertyValueCollection&lt;/FONT&gt; pv)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;object&lt;/FONT&gt; o;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (pv == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; || (o = pv.Value) == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.Convert(o);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; SetValue(&lt;FONT Color=#2b91af&gt;PropertyValueCollection&lt;/FONT&gt; pv, &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; value)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (pv.Value == value) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (value == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;pv.Remove(pv.Value);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (pv.Value &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IADsLargeInteger&lt;/FONT&gt; &amp;amp&amp;amp value &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#008000&gt;&lt;div style="margin-left:20pt"&gt;//pv.Value = (int)(uint)((DateTime)value).ToFileTime();&lt;/FONT&gt;&lt;FONT Color=#2b91af&gt;&lt;br&gt;ActiveDirectory&lt;/FONT&gt;.SetDateTime(pv, (&lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;)value);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;pv.Value = value;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:20pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; The default 'objectClass' types on which a search can be performed&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;enum&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;any, group, user, organizationalUnit, computer, container&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:20pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Interface type to convert AD date time objects&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;br&gt;[&lt;FONT Color=#2b91af&gt;ComImport&lt;/FONT&gt;]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;Guid&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quot9068270B-0939-11D1-8BE1-00C04FD8D503&amp;quot&lt;/FONT&gt;)]&lt;br&gt;[&lt;FONT Color=#2b91af&gt;InterfaceType&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;ComInterfaceType&lt;/FONT&gt;.InterfaceIsDual)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;interface&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IADsLargeInteger&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;[&lt;FONT Color=#2b91af&gt;DispId&lt;/FONT&gt;(0x00000002)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;int&lt;/FONT&gt; HighPart { &lt;FONT Color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT Color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;br&gt;[&lt;FONT Color=#2b91af&gt;DispId&lt;/FONT&gt;(0x00000003)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;int&lt;/FONT&gt; LowPart { &lt;FONT Color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT Color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:20pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Static functions for querying Active Directory&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;#region&lt;/FONT&gt; Main get entries functions&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEntries(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Filter)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEntries(Filter, (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEntries(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Filter, &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; RootFilter)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ActiveDirectoryEntry&lt;/FONT&gt; root = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (RootFilter != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;root = GetFirstEntry(RootFilter);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; GetEntries(Filter, root);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEntries(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Filter, &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; root)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEntries(Filter, root, &lt;FONT Color=#2b91af&gt;SearchScope&lt;/FONT&gt;.Subtree);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEntries(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Filter, &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; Root, &lt;FONT Color=#2b91af&gt;SearchScope&lt;/FONT&gt; Scope)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;AdSearchInfo&lt;/FONT&gt; si = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AdSearchInfo&lt;/FONT&gt;();&lt;br&gt;si.SearchRoot = Root;&lt;br&gt;si.Scope = Scope;&lt;br&gt;si.Filter = Filter;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; si;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEntries(&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt; ObjectClass)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEntries(&lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(ObjectClass));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetFirstEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Filter)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetFirstEntry(Filter, &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetFirstEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Filter, &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; root)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetFirstEntry(GetEntries(Filter, root));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetFirstEntry(&lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt ie)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; ie)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; de;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#endregion&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; Specific entry searching/ supporting functions&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetFolder(&lt;FONT Color=#0000ff&gt;params&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;[] Path)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ActiveDirectoryEntry&lt;/FONT&gt; de = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; Path)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;de = GetFolder(s, de);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (de == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; de;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetFolder(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; name, &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; parent)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; de &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; GetFolders(name, parent))&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; de;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetFolders(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; name, &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; parent)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.IsNullOrEmpty(name)) name = &lt;FONT Color=#a31515&gt;&amp;quot*&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; GetEntries(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.Format( &lt;FONT Color=#008000&gt;//&amp;quot(|(&amp;amp(cn={0})(objectClass=group))(ou={0}))&amp;quot&lt;/FONT&gt;&lt;FONT Color=#a31515&gt;&lt;div style="margin-left:20pt"&gt;&amp;quot(ou={0})&amp;quot&lt;/FONT&gt;, name), parent, &lt;FONT Color=#2b91af&gt;SearchScope&lt;/FONT&gt;.OneLevel);&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetContainers()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetContainers(&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetContainers(&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; parent)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEntries(&lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.container));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetSecurityGroup(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; group)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetFirstEntry(GetFilter(group, &lt;FONT Color=#a31515&gt;&amp;quotgroup&amp;quot&lt;/FONT&gt;));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetBySID(System.Security.Principal.&lt;FONT Color=#2b91af&gt;SecurityIdentifier&lt;/FONT&gt; sid)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetBySID(sid.Value);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetBySID(&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[] sid)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;StringBuilder&lt;/FONT&gt; sb = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;StringBuilder&lt;/FONT&gt;();&lt;FONT Color=#0000ff&gt;&lt;br&gt;for&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt sid.Length; i++)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (sid[i] &amp;lt 33 || sid[i] &amp;gt 125)&lt;div style="margin-left:20pt"&gt;sb.Append(&lt;FONT Color=#a31515&gt;&amp;quot\\&amp;quot&lt;/FONT&gt;).Append(sid[i].ToString(&lt;FONT Color=#a31515&gt;&amp;quotx2&amp;quot&lt;/FONT&gt;));&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;sb.Append((&lt;FONT Color=#0000ff&gt;char&lt;/FONT&gt;)sid[i]);&lt;/div&gt;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; GetBySID(sb.ToString());&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetBySID(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; sid)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetFirstEntry(&lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quotobjectSid&amp;quot&lt;/FONT&gt;, sid));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; System.Security.Principal.&lt;FONT Color=#2b91af&gt;SecurityIdentifier&lt;/FONT&gt; GetSID(&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[] value)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; System.Security.Principal.&lt;FONT Color=#2b91af&gt;SecurityIdentifier&lt;/FONT&gt;(value, 0);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; cn)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEntry(cn, &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;);&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; cn, &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; objectclass)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetFirstEntry(GetFilter(cn, objectclass));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetEntry(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; cn, &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt; objectclass)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEntry(cn, objectclass.ToString());&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; GetFilter(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; cn, &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; objectclass)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADFilter&lt;/FONT&gt; filter = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;br&gt;filter.objectClass = objectclass;&lt;br&gt;filter[&lt;FONT Color=#a31515&gt;&amp;quotcn&amp;quot&lt;/FONT&gt;] = cn == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; ? &lt;FONT Color=#a31515&gt;&amp;quot*&amp;quot&lt;/FONT&gt; : cn;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; filter;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;#endregion&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; Other AD related functions&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; SynchronizeDomain(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; TargetServer)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;ad.&lt;FONT Color=#2b91af&gt;DirectoryContext&lt;/FONT&gt; context = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; ad.&lt;FONT Color=#2b91af&gt;DirectoryContext&lt;/FONT&gt;(ad.&lt;FONT Color=#2b91af&gt;DirectoryContextType&lt;/FONT&gt;.DirectoryServer, TargetServer);&lt;FONT Color=#0000ff&gt;&lt;br&gt;int&lt;/FONT&gt; res = 0;&lt;FONT Color=#0000ff&gt;&lt;br&gt;using&lt;/FONT&gt; (ad.&lt;FONT Color=#2b91af&gt;DomainController&lt;/FONT&gt; dc = ad.&lt;FONT Color=#2b91af&gt;DomainController&lt;/FONT&gt;.GetDomainController(context))&lt;br&gt;{&lt;FONT Color=#008000&gt;&lt;div style="margin-left:20pt"&gt;//dc.SyncReplicaFromAllServers(&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; partition &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; dc.Partitions)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;dc.SyncReplicaFromAllServers(partition, ad.&lt;FONT Color=#2b91af&gt;SyncFromAllServersOptions&lt;/FONT&gt;.AbortIfServerUnavailable);&lt;br&gt;res++;&lt;/div&gt;}&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; res;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;ltad.&lt;FONT Color=#2b91af&gt;DomainController&lt;/FONT&gt;&amp;gt GetDomainControllers()&lt;br&gt;{&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;foreach&lt;/FONT&gt; (ad.&lt;FONT Color=#2b91af&gt;DomainController&lt;/FONT&gt; dc &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; ad.&lt;FONT Color=#2b91af&gt;Domain&lt;/FONT&gt;.GetCurrentDomain().DomainControllers)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; dc;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;&amp;gt GetDomainServers()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (ad.&lt;FONT Color=#2b91af&gt;DomainController&lt;/FONT&gt; dc &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; GetDomainControllers())&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; dc.Name;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#endregion&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; DateTime support&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; IsDateTimeComObject(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; o)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; o &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IADsLargeInteger&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Converts an &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsee cref=&amp;quotIADsLargeInteger&amp;quot/&amp;gt&lt;/FONT&gt;&lt;FONT Color=#008000&gt; to a date time&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltparam name=&amp;quotComObject&amp;quot&amp;gt&amp;lt/param&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltreturns&amp;gt&amp;lt/returns&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt; GetDateTime(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; ComObject)&lt;br&gt;{&lt;/div&gt;&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:60pt"&gt;IADsLargeInteger&lt;/FONT&gt; li = (&lt;FONT Color=#2b91af&gt;IADsLargeInteger&lt;/FONT&gt;)ComObject;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (li.LowPart == -1) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;.MinValue;&lt;FONT Color=#0000ff&gt;&lt;br&gt;long&lt;/FONT&gt; date = (&lt;FONT Color=#0000ff&gt;long&lt;/FONT&gt;)li.HighPart &amp;lt&amp;lt 32 | (&lt;FONT Color=#0000ff&gt;uint&lt;/FONT&gt;)li.LowPart;&lt;FONT Color=#0000ff&gt;&lt;br&gt;try&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;.FromFileTime(date);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;catch&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;Exception&lt;/FONT&gt; ex)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;System.Diagnostics.&lt;FONT Color=#2b91af&gt;Debug&lt;/FONT&gt;.WriteLine(ex.Message);&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;.MinValue;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;const&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;long&lt;/FONT&gt; lowmask = 0xFFFFFFFF;&lt;FONT Color=#0000ff&gt;&lt;br&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; SetDateTime(&lt;FONT Color=#2b91af&gt;PropertyValueCollection&lt;/FONT&gt; pv, &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt; value)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;IADsLargeInteger&lt;/FONT&gt; li = (&lt;FONT Color=#2b91af&gt;IADsLargeInteger&lt;/FONT&gt;)pv.Value;&lt;FONT Color=#0000ff&gt;&lt;br&gt;long&lt;/FONT&gt; l = value.ToFileTime();&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:60pt"&gt;li.HighPart = (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt;)(l &amp;gt&amp;gt 32);&lt;br&gt;li.LowPart = (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt;)(l &amp;amp lowmask);&lt;FONT Color=#008000&gt;&lt;br&gt;//Forces update&lt;/FONT&gt;&lt;br&gt;pv.Value = li;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Formats the DateTime to LDIF&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltparam name=&amp;quotdt&amp;quot&amp;gt&amp;lt/param&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltreturns&amp;gt&amp;lt/returns&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; FormatDateTime(&lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt; dt)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; dt.ToString(&lt;FONT Color=#a31515&gt;@&amp;quotyyMMddHHmmssZ&amp;quot&lt;/FONT&gt;);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; FormatBoolean(&lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; b)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; b ? &lt;FONT Color=#a31515&gt;&amp;quotTRUE&amp;quot&lt;/FONT&gt; : &lt;FONT Color=#a31515&gt;&amp;quotFALSE&amp;quot&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;#endregion&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; Conversion&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; Convert(&lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; o)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (IsDateTimeComObject(o))&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetDateTime(o);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (o &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[])&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;byte&lt;/FONT&gt;[] b = (&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[])o;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (b.Length == 16)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Guid&lt;/FONT&gt;(b);&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#008000&gt;&lt;div style="margin-left:60pt"&gt;//TODO: other com objects&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; o;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;internal&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ByteArrayToString(&lt;FONT Color=#0000ff&gt;byte&lt;/FONT&gt;[] b)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;StringBuilder&lt;/FONT&gt; sb = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;StringBuilder&lt;/FONT&gt;(&lt;FONT Color=#a31515&gt;&amp;quot0x &amp;quot&lt;/FONT&gt;);&lt;FONT Color=#0000ff&gt;&lt;br&gt;for&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;int&lt;/FONT&gt; i = 0; i &amp;lt b.Length; i++)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;sb.Append(b[i].ToString(&lt;FONT Color=#a31515&gt;&amp;quotX&amp;quot&lt;/FONT&gt;));&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; sb.ToString();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#endregion&lt;/div&gt;&lt;br&gt;&lt;br&gt;#if&lt;/FONT&gt; Framework30&lt;br&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;/// &amp;ltsummary&amp;gt&lt;br&gt;/// Used for querying with Linq&lt;br&gt;/// &amp;lt/summary&amp;gt&lt;br&gt;public static ADQuery Entries&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;get&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return new ADQuery();&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;public static ADQuery&amp;ltUserInfo&amp;gt Users&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;get&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return new ADQuery&amp;ltUserInfo&amp;gt(UserInfo.GetDefaultUserGroupsFilter());&lt;/div&gt;}&lt;/div&gt;}&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;#endif&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;#region&lt;/FONT&gt; Filter&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;interface&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt;&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; : &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt;&amp;gt, &lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; ADFilter()&lt;br&gt;{&lt;br&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ADFilter(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property, &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Value)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;[Property] = Value;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ADFilter(&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt; ObjectClass)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.ObjectClass = ObjectClass;&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt; LogicalOperator;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ToString()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (Count == 0) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (Count == 1) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[0].ToString();&lt;FONT Color=#0000ff&gt;&lt;br&gt;string&lt;/FONT&gt; s = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt; c &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;s += c.ToString();&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.Format(&lt;FONT Color=#a31515&gt;&amp;quot({0}{1})&amp;quot&lt;/FONT&gt;, GetOperator(), s);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;string&lt;/FONT&gt; GetOperator()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;switch&lt;/FONT&gt; (LogicalOperator)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;case&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt;.AND:&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#a31515&gt;&amp;quot&amp;amp&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;case&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt;.OR:&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#a31515&gt;&amp;quot|&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;case&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt;.NOT:&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#a31515&gt;&amp;quot!&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;default&lt;/FONT&gt;:&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Gets or sets the criterium for the secified property. If a property is set that was set&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; in a previous step, the previous property criterium will be overridden. For adding&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; multiple criteria of the same property, please use &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsee cref=&amp;quotAdd&amp;quot/&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltparam name=&amp;quotProperty&amp;quot&amp;gt&amp;lt/param&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltreturns&amp;gt&amp;lt/returns&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property]&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADCriterium&lt;/FONT&gt; c = GetCriterium(Property);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (c == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; c.Value;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADCriterium&lt;/FONT&gt; c = GetCriterium(Property);&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (c == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt; != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) Add(Property, &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;else&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt; == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;Remove(c);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;c.Value = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; Add(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property, &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; value)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Add(&lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADCriterium&lt;/FONT&gt;(Property, value));&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; AddSubFilter(&lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt; Operator)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADFilter&lt;/FONT&gt; filter = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;br&gt;filter.LogicalOperator = Operator;&lt;br&gt;Add(filter);&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; filter;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; AddSubFilter(&lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt; Operator,&lt;FONT Color=#0000ff&gt;params&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt;[] criteria)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADFilter&lt;/FONT&gt; filter = AddSubFilter(Operator);&lt;br&gt;filter.AddRange(criteria);&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; filter;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; GetFirstEntry()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.GetFirstEntry(GetEntries());&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEntries()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AdSearchInfo&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADCriterium&lt;/FONT&gt; GetCriterium(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt; ic &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADCriterium&lt;/FONT&gt; c = ic &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADCriterium&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (c != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; &amp;amp&amp;amp &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.Equals(c.Property, Property, &lt;FONT Color=#2b91af&gt;StringComparison&lt;/FONT&gt;.OrdinalIgnoreCase))&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; c;&lt;/div&gt;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;[System.ComponentModel.&lt;FONT Color=#2b91af&gt;DefaultValue&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; objectClass&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#a31515&gt;&amp;quotobjectClass&amp;quot&lt;/FONT&gt;] &lt;FONT Color=#0000ff&gt;as&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;[&lt;FONT Color=#a31515&gt;&amp;quotobjectClass&amp;quot&lt;/FONT&gt;] = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;[System.ComponentModel.&lt;FONT Color=#2b91af&gt;DesignerSerializationVisibility&lt;/FONT&gt;(System.ComponentModel.&lt;FONT Color=#2b91af&gt;DesignerSerializationVisibility&lt;/FONT&gt;.Hidden)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt; ObjectClass&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;string&lt;/FONT&gt; s = objectClass;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (s == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.any;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;)&lt;FONT Color=#2b91af&gt;Enum&lt;/FONT&gt;.Parse(&lt;FONT Color=#0000ff&gt;typeof&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;), s);&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt; == &lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt;.any)&lt;div style="margin-left:20pt"&gt;objectClass = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;else&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;objectClass = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;.ToString();&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;implicit&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;operator&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; f)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (f == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; f.ToString();&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;implicit&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;operator&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; s)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.IsNullOrEmpty(s)) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#2b91af&gt;&lt;br&gt;ADFilter&lt;/FONT&gt; f = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;br&gt;f.Add(&lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLiteralCriterium&lt;/FONT&gt;(s));&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; f;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;implicit&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;operator&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;ADCriterium&lt;/FONT&gt; c)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADFilter&lt;/FONT&gt; f = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;br&gt;f.Add(c);&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; f;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;static&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;implicit&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;operator&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;DefaultClass&lt;/FONT&gt; cl)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADFilter&lt;/FONT&gt; f = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;br&gt;f.ObjectClass = cl;&lt;FONT Color=#0000ff&gt;&lt;br&gt;return&lt;/FONT&gt; f;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;AdSearchInfo&lt;/FONT&gt;:&lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;ADFilter&lt;/FONT&gt; filter;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; SearchRoot;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;&amp;gt PropertiesToLoad;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;SearchScope&lt;/FONT&gt; Scope = &lt;FONT Color=#2b91af&gt;SearchScope&lt;/FONT&gt;.Subtree;&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; AdSearchInfo()&lt;br&gt;{&lt;br&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; AdSearchInfo(&lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; Filter)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.filter = Filter;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; AdSearchInfo(&lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; Filter, &lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;&amp;gt PropertiesToLoad):&lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;(Filter)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.PropertiesToLoad = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;&amp;gt(PropertiesToLoad);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt; Filter&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (filter == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;filter = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADFilter&lt;/FONT&gt;();&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; filter;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;filter = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;void&lt;/FONT&gt; AddLoadProperty(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; prop)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (PropertiesToLoad == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;)&lt;div style="margin-left:20pt"&gt;PropertiesToLoad = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;List&lt;/FONT&gt;&amp;lt&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;&amp;gt();&lt;/div&gt;PropertiesToLoad.Add(prop);&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; IEnumerable&amp;ltActiveDirectoryEntry&amp;gt Members&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;IEnumerator&lt;/FONT&gt;&amp;lt&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;&amp;gt GetEnumerator()&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;DirectoryEntry&lt;/FONT&gt; root = SearchRoot == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; ? &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DirectoryEntry&lt;/FONT&gt;() : SearchRoot.Entry;&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:60pt"&gt;using&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;DirectorySearcher&lt;/FONT&gt; ds = &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DirectorySearcher&lt;/FONT&gt;(root, filter,&lt;div style="margin-left:20pt"&gt;PropertiesToLoad==&lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; ? &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; : PropertiesToLoad.ToArray()))&lt;/div&gt;{&lt;div style="margin-left:20pt"&gt;ds.SearchScope = Scope;&lt;FONT Color=#2b91af&gt;&lt;br&gt;SearchResultCollection&lt;/FONT&gt; res = ds.FindAll();&lt;FONT Color=#0000ff&gt;&lt;br&gt;foreach&lt;/FONT&gt; (&lt;FONT Color=#2b91af&gt;SearchResult&lt;/FONT&gt; sr &lt;FONT Color=#0000ff&gt;in&lt;/FONT&gt; res)&lt;br&gt;{&lt;FONT Color=#2b91af&gt;&lt;div style="margin-left:20pt"&gt;DirectoryEntry&lt;/FONT&gt; de = sr.GetDirectoryEntry();&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (de.Name != root.Name)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;yield&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt;(de);&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;} &lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#endregion&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; IEnumerable Members&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;System.Collections.&lt;FONT Color=#2b91af&gt;IEnumerator&lt;/FONT&gt; System.Collections.&lt;FONT Color=#2b91af&gt;IEnumerable&lt;/FONT&gt;.GetEnumerator()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; GetEnumerator();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#endregion&lt;/FONT&gt;&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;enum&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLogicalOperator&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;AND, OR, NOT&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;[&lt;FONT Color=#2b91af&gt;Flags&lt;/FONT&gt;]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;enum&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Equals = 1,&lt;br&gt;Approxamately = 3,&lt;br&gt;GreaterThan = 4,&lt;br&gt;LessThan = 8&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADCriterium&lt;/FONT&gt; : &lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property;&lt;br&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Operator, can be combined (eg combine &amp;quot&amp;gt&amp;quot and &amp;quot=&amp;quot to get &amp;quot&amp;gt=&amp;quot )&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt; Operator;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; Value;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ADCriterium(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property, &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; Value)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.Property = Property;&lt;FONT Color=#0000ff&gt;&lt;br&gt;this&lt;/FONT&gt;.Value = Value;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ADCriterium(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Property, &lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt; Operator, &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; Value)&lt;div style="margin-left:20pt"&gt;: &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;(Property, Value)&lt;/div&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.Operator = Operator;&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; GetFormattedValue()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (Value == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (Value &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.FormatDateTime((&lt;FONT Color=#2b91af&gt;DateTime&lt;/FONT&gt;)Value);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (Value &lt;FONT Color=#0000ff&gt;is&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt;)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectory&lt;/FONT&gt;.FormatBoolean((&lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt;)Value);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; Value.ToString();&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;bool&lt;/FONT&gt; Implements(&lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt; o)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; (o &amp;amp &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;.Operator) == o;&lt;/div&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;string&lt;/FONT&gt; GetOperator()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (Operator == 0) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT Color=#a31515&gt;&amp;quot=&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;string&lt;/FONT&gt; res = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;br&gt;if&lt;/FONT&gt; (Implements(&lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt;.Approxamately))&lt;div style="margin-left:20pt"&gt;res += &lt;FONT Color=#a31515&gt;&amp;quot~&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (Implements(&lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt;.LessThan))&lt;div style="margin-left:20pt"&gt;res += &lt;FONT Color=#a31515&gt;&amp;quot&amp;lt&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (Implements(&lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt;.GreaterThan))&lt;div style="margin-left:20pt"&gt;res += &lt;FONT Color=#a31515&gt;&amp;quot&amp;gt&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;if&lt;/FONT&gt; (Implements(&lt;FONT Color=#2b91af&gt;Operator&lt;/FONT&gt;.Equals))&lt;div style="margin-left:20pt"&gt;res += &lt;FONT Color=#a31515&gt;&amp;quot=&amp;quot&lt;/FONT&gt;;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; res;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ToString()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.Format(&lt;FONT Color=#a31515&gt;&amp;quot({0}{1}{2})&amp;quot&lt;/FONT&gt;, Property, GetOperator(), GetFormattedValue());&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ADLiteralCriterium&lt;/FONT&gt; : &lt;FONT Color=#2b91af&gt;IADCriterium&lt;/FONT&gt;&lt;br&gt;{&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Criterium;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ADLiteralCriterium(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Criterium)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.Criterium = Criterium;&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;override&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; ToString()&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;return&lt;/FONT&gt; Criterium;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;#endregion&lt;/div&gt;&lt;br&gt;#if&lt;/FONT&gt; Framework30&lt;FONT Color=#808080&gt;&lt;div style="margin-left:20pt"&gt;public class ADQuery&amp;ltT&amp;gt &lt;br&gt;{&lt;div style="margin-left:20pt"&gt;AdSearchInfo inf;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;public ADQuery() :&lt;div style="margin-left:20pt"&gt;this(null)&lt;/div&gt;{&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;public ADQuery(ADFilter filter)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;this.inf = new AdSearchInfo(filter);&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;public ADQuery&amp;ltT&amp;gt Where(Expression&amp;ltFunc&amp;ltT,bool&amp;gt&amp;gt predicate)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;Add(predicate,inf.Filter);&lt;br&gt;return this;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;bool Add(Expression e,ADFilter filter)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (e is LambdaExpression)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return Add(((LambdaExpression)e).Body, filter);&lt;/div&gt;}&lt;br&gt;if (e is BinaryExpression)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;var b= e as BinaryExpression;&lt;br&gt;ADLogicalOperator op = filter.LogicalOperator;&lt;br&gt;if (b.NodeType == ExpressionType.NotEqual)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;filter = filter.AddSubFilter(ADLogicalOperator.NOT);&lt;/div&gt;}&lt;br&gt;else if (b.NodeType == ExpressionType.AndAlso)&lt;div style="margin-left:20pt"&gt;return Add(b, filter, ADLogicalOperator.AND);&lt;/div&gt;else if(b.NodeType== ExpressionType.OrElse)&lt;div style="margin-left:20pt"&gt;return Add(b, filter, ADLogicalOperator.OR);&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:80pt"&gt;return Add(b.Left,GetOperator(b.NodeType),b.Right,filter);&lt;/div&gt;&lt;div style="margin-left:60pt"&gt;}&lt;br&gt;if (e is MethodCallExpression)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;var m = e as MethodCallExpression;&lt;br&gt;var name = m.Method.Name;&lt;br&gt;if (m.Arguments.Count == 1)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (name == &amp;quotEquals&amp;quot)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return Add(m, Operator.Equals, m.Arguments[0], filter);&lt;/div&gt;}&lt;br&gt;if (m.Arguments[0].Type == typeof(string))&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;string val =(string) (m.Arguments[0] as ConstantExpression).Value;&lt;br&gt;if (name == &amp;quotStartsWith&amp;quot)&lt;div style="margin-left:20pt"&gt;val += &amp;quot*&amp;quot;&lt;/div&gt;else if (name == &amp;quotEndsWith&amp;quot)&lt;div style="margin-left:20pt"&gt;val = &amp;quot*&amp;quot + val;&lt;/div&gt;else if (name == &amp;quotContains&amp;quot)&lt;div style="margin-left:20pt"&gt;val = &amp;quot*&amp;quot + val + &amp;quot*&amp;quot;&lt;/div&gt;else&lt;div style="margin-left:20pt"&gt;val = null;&lt;/div&gt;if(val!=null)&lt;div style="margin-left:20pt"&gt;return Add(m, Operator.Equals, val, filter);&lt;/div&gt;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;}&lt;br&gt;throw new NotSupportedException();&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;bool Add(Expression prop, Operator op, object value, ADFilter filter)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;filter.Add(&lt;div style="margin-left:40pt"&gt;new ADCriterium(&lt;div style="margin-left:20pt"&gt;GetProperty(prop), op, GetValue(value)));&lt;/div&gt;&lt;/div&gt;return true;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;bool Add(BinaryExpression b, ADFilter filter, ADLogicalOperator op)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (op != filter.LogicalOperator)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;filter.Add(filter = new ADFilter());&lt;br&gt;filter.LogicalOperator = op;&lt;/div&gt;}&lt;br&gt;return Add(b.Left, filter)&lt;div style="margin-left:20pt"&gt;&amp;amp&amp;amp Add(b.Right, filter);&lt;/div&gt;&lt;/div&gt;}&lt;br&gt;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;string GetProperty(Expression e)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (e is MethodCallExpression)&lt;br&gt;{&lt;br&gt;}&lt;br&gt;if (e is LambdaExpression)&lt;div style="margin-left:20pt"&gt;return GetProperty((e as LambdaExpression).Body);&lt;/div&gt;if (e is MemberExpression)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;var mi = (e as MemberExpression).Member;&lt;br&gt;foreach (ActiveDirectoryAliasAttribute alias in&lt;div style="margin-left:20pt"&gt;mi.GetCustomAttributes(typeof(ActiveDirectoryAliasAttribute),true))&lt;/div&gt;{&lt;div style="margin-left:20pt"&gt;return alias.Alias;&lt;/div&gt;}&lt;br&gt;return mi.Name;&lt;/div&gt;}&lt;br&gt;if (e is MethodCallExpression)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return GetProperty((e as MethodCallExpression).Object);&lt;/div&gt;}&lt;br&gt;throw new NotSupportedException();&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;object GetValue(object e)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (e is Expression)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (e is ConstantExpression)&lt;div style="margin-left:20pt"&gt;return (e as ConstantExpression).Value;&lt;/div&gt;throw new NotSupportedException();&lt;/div&gt;}&lt;br&gt;return e;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;Operator GetOperator(ExpressionType type)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;if (type == ExpressionType.Equal || type== ExpressionType.NotEqual)&lt;div style="margin-left:20pt"&gt;return Operator.Equals;&lt;/div&gt;if (type == ExpressionType.LessThan)&lt;div style="margin-left:20pt"&gt;return Operator.LessThan;&lt;/div&gt;if (type == ExpressionType.LessThanOrEqual)&lt;div style="margin-left:20pt"&gt;return Operator.LessThan | Operator.Equals;&lt;/div&gt;if (type == ExpressionType.GreaterThan)&lt;div style="margin-left:20pt"&gt;return Operator.GreaterThan;&lt;/div&gt;if (type == ExpressionType.GreaterThanOrEqual)&lt;div style="margin-left:20pt"&gt;return Operator.GreaterThan | Operator.Equals;&lt;/div&gt;throw new NotSupportedException();&lt;/div&gt;}&lt;br&gt;&lt;br&gt;public IEnumerable&amp;ltActiveDirectoryEntry&amp;gt Select(Expression&amp;ltFunc&amp;ltT,ADQuery&amp;ltT&amp;gt&amp;gt&amp;gt selector)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;return inf;&lt;/div&gt;}&lt;br&gt;&lt;br&gt;public IEnumerable&amp;ltS&amp;gt Select&amp;ltS&amp;gt(Expression&amp;ltFunc&amp;ltT, S&amp;gt&amp;gt selector)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;var ne = (selector as LambdaExpression).Body as NewExpression;&lt;br&gt;if (ne != null)&lt;div style="margin-left:20pt"&gt;return Select&amp;ltS&amp;gt(ne);&lt;/div&gt;return Select&amp;ltS&amp;gt(GetProperty(selector));&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;IEnumerable&amp;ltS&amp;gt Select&amp;ltS&amp;gt(string prop)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;inf.AddLoadProperty(prop);&lt;br&gt;foreach (var entry in inf)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;yield return entry.GetValue&amp;ltS&amp;gt(prop);&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;IEnumerable&amp;ltS&amp;gt Select&amp;ltS&amp;gt(NewExpression ne)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;string[] props = new string[ne.Arguments.Count];&lt;br&gt;object[] pars = new object[props.Length];&lt;br&gt;int i = 0;&lt;br&gt;foreach (Expression e in ne.Arguments)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;inf.AddLoadProperty( props[i++] = GetProperty(e));&lt;/div&gt;}&lt;br&gt;foreach (var entry in inf)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;for (i = 0; i &amp;lt props.Length; i++)&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;pars[i] = entry[props[i]];&lt;/div&gt;}&lt;br&gt;S res =(S) ne.Constructor.Invoke(pars);&lt;br&gt;yield return res;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;public class ADQuery:ADQuery&amp;ltActiveDirectoryEntry&amp;gt&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;public ADQuery() :&lt;div style="margin-left:20pt"&gt;base()&lt;/div&gt;{&lt;br&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;public ADQuery(ADFilter filter):base(filter)&lt;br&gt;{&lt;br&gt;}&lt;/div&gt;&lt;div style="margin-left:20pt"&gt;}&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;/div&gt;#endif&lt;br&gt;&lt;/FONT&gt;&lt;div style="margin-left:20pt"&gt;[&lt;FONT Color=#2b91af&gt;AttributeUsage&lt;/FONT&gt;(&lt;FONT Color=#2b91af&gt;AttributeTargets&lt;/FONT&gt;.Field | &lt;FONT Color=#2b91af&gt;AttributeTargets&lt;/FONT&gt;.Property)]&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryAliasAttribute&lt;/FONT&gt;:&lt;FONT Color=#2b91af&gt;Attribute&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;readonly&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Alias;&lt;FONT Color=#0000ff&gt;&lt;br&gt;public&lt;/FONT&gt; ActiveDirectoryAliasAttribute(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Alias)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.Alias = Alias;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;partial&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;class&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;UserInfo&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;public&lt;/FONT&gt; UserInfo(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; Name)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.name = Name;&lt;/div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#808080&gt;&lt;div style="margin-left:40pt"&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; The scope of this constructor is not made public because that would force projects&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; referencing the project with this code to have a reference to System.DirectoryServices.&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; Use GetInfo(ActiveDirectoryEntry) instead&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;FONT Color=#808080&gt;&lt;br&gt;///&lt;/FONT&gt;&lt;FONT Color=#008000&gt; &lt;/FONT&gt;&lt;FONT Color=#808080&gt;&amp;ltparam name=&amp;quotActiveDirectoryEntry&amp;quot&amp;gt&amp;lt/param&amp;gt&lt;/FONT&gt;&lt;FONT Color=#0000ff&gt;&lt;br&gt;protected&lt;/FONT&gt; UserInfo(&lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ActiveDirectoryEntry)&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;this&lt;/FONT&gt;.ActiveDirectoryEntry = ActiveDirectoryEntry;&lt;/div&gt;}&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;#region&lt;/FONT&gt; AD&lt;FONT Color=#2b91af&gt;&lt;br&gt;ActiveDirectoryEntry&lt;/FONT&gt; adEntry;&lt;/div&gt;&lt;br&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; ActiveDirectoryEntry&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:80pt"&gt;if&lt;/FONT&gt; (!HasActiveDirectoryEntry)&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;throw&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;new&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;Exception&lt;/FONT&gt;(name + &lt;FONT Color=#a31515&gt;&amp;quot&amp;nbsp&amp;nbspniet gevonden&amp;quot&lt;/FONT&gt;);&lt;/div&gt;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:80pt"&gt;return&lt;/FONT&gt; adEntry;&lt;/div&gt;&lt;div style="margin-left:60pt"&gt;}&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (adEntry == &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;) &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt;;&lt;br&gt;adEntry = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;br&gt;name = &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;&lt;div style="margin-left:40pt"&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;bool&lt;/FONT&gt; HasActiveDirectoryEntry&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt;&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;if&lt;/FONT&gt; (adEntry == &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt; &amp;amp&amp;amp !&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt;.IsNullOrEmpty(name))&lt;div style="margin-left:20pt"&gt;adEntry = Search(name);&lt;FONT Color=#0000ff&gt;&lt;/div&gt;return&lt;/FONT&gt; adEntry != &lt;FONT Color=#0000ff&gt;null&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;object&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;this&lt;/FONT&gt;[&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; PropertyName]&lt;br&gt;{&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:20pt"&gt;get&lt;/FONT&gt; { &lt;FONT Color=#0000ff&gt;return&lt;/FONT&gt; ActiveDirectoryEntry[PropertyName]; }&lt;FONT Color=#0000ff&gt;&lt;br&gt;set&lt;/FONT&gt;&lt;br&gt;{&lt;div style="margin-left:20pt"&gt;ActiveDirectoryEntry[PropertyName] = &lt;FONT Color=#0000ff&gt;value&lt;/FONT&gt;;&lt;/div&gt;}&lt;/div&gt;}&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;public&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;const&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; NameSearchField = &lt;FONT Color=#a31515&gt;&amp;quotsAMAccountName&amp;quot&lt;/FONT&gt;;&lt;/div&gt;&lt;FONT Color=#0000ff&gt;&lt;div style="margin-left:40pt"&gt;protected&lt;/FONT&gt; &lt;FONT Color=#0000ff&gt;virtual&lt;/FONT&gt; &lt;FONT Color=#2b91af&gt;ActiveDirectoryEntry&lt;/FONT&gt; Search(&lt;FONT Color=#0000ff&gt;string&lt;/FONT&gt; name)&lt;br&gt