views:

66

answers:

1

First, I wish to write myself a generic type for operations against the underlying Active Directory.

For those of you who know about AD and the System.DirectoryServices namespace, the DirectoryEntry class is the top most important along with the DirectorySearcher class.

When speaking the AD language, everything is a DirectoryEntry. With that said, my application needs to manage Users, Groups and Organizational Units (OU). Each of these objects are AD entries. Then, this sounds to me a good candidate for GenericTypes.

What I wish to accomplish is this:

public interface ITop {
    string Path { get; set; }
    string ObjectClass { get; }
    string ContainerName { get; set; }
    // [...]
}

public interface IGroup : ITop {
    // Speciality properties here...
}

public interface IUser : ITop {
    // Speciality properties here...
}

// And so forth...

public sealed class DirectorySource<T> where T : ITop {
    // Methods against AD here...
}

My class library MUST respond to the following organical criterion:

  1. VS2005 VBNET
  2. .NET 2.0
  3. Active Directory
  4. Windows Forms

Well, I guess I have already given too much details for the purpose of my question, but any suggestion on the architecture and design patterns are welcome as well. My question is:

Is there a VBNET 2.0 equivalence of C# where (generic type constraint) keyword, or any best practice workarounds?

The results of my searches seem to end with the undoable conclusion. So I'm asking...

+5  A: 

Like this:

Public Class DirectorySource(Of T As ITop)

Multiple constraints are enclosed by braces, like this:

Public Class DirectorySource(Of T As { ITop, IDisposable, Class, New })
SLaks
You would think that it would be something like this `Of T As One Of The Following Items ITop, IDisposable, Class, New`
ChaosPandion
@ChaosPandion: Generic constraints are anded, not ored.
SLaks
+1 Simple, lean, and swift, just like we like those answers! Thanks SLaks! =)
Will Marcouiller