Any VBNET equivalence of C# where generic constraint keyword?

自作多情 提交于 2020-02-27 15:08:21

问题


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...


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!