Last post Apr 04, 2011 02:19 PM by strato1986
Apr 01, 2011 09:53 PM|strato1986|LINK
I have been able to extend the system class DirectoryEntry by adding static methods like setSAMAccountName, setMail, setPassword, etc.
But my goal is to set them like parameters in the form of de.Mail = email@example.com...
Is there a way of doing this without extending the DirectoryEntry class? becose when i run the code de.Childen.Add ... the method implementation returns a DirectoryEntry and not my extended class.
Is there a way of COMPLETELY extend this class?
Apr 02, 2011 06:52 AM|akhhttar|LINK
I would like you to use Composition, means create a new layer on the top of DirectoryEntry. Create a new class and DirectoryEntry should be a private member of it. Expose the smiliar methods as in DirectoryEntry, these methods will be using DirectoryEntry
internally but they will return the instance of you own object. Similary you can also create new properties for that class.
Hope it helps
Apr 04, 2011 10:25 AM|strato1986|LINK
Thanks! can you post an example?
My goal is to have full control on the Childen.Add method (so it return an instance of MY object instead of DirectoryEntry)
Apr 04, 2011 01:25 PM|akhhttar|LINK
Hope this code will help you to get an idea,
public class MyDirectoryEntry : DirectoryEntry
private DirectoryEntry _directoryEntry;
public MyDirectoryEntry(string path, string userName, string password)
_directoryEntry = new DirectoryEntry(path, userName, password);
private MyDirectoryEntry(DirectoryEntry directoryEntry)
_directoryEntry = directoryEntry;
#region Public Methods
public MyDirectoryEntry AddChild(string childName, string childSchemaClass)
DirectoryEntry _childEntry = _directoryEntry.Children.Add(childName, childSchemaClass);
return new MyDirectoryEntry(_childEntry);
Apr 04, 2011 02:19 PM|strato1986|LINK
Yeah! i was really close to this though :)
Thank you very much it helped me a lot!