问题
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:
- VS2005 VBNET
- .NET 2.0
- Active Directory
- 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...
回答1:
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 })
来源:https://stackoverflow.com/questions/2803933/any-vbnet-equivalence-of-c-sharp-where-generic-constraint-keyword