通用约束关键字在C#的任何VBNET等效项中? [英] Any VBNET equivalence of C# where generic constraint keyword?

查看:80
本文介绍了通用约束关键字在C#的任何VBNET等效项中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想为自己编写一个用于对基础Active Directory进行操作的通用类型。

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

对于那些了解AD和 System.DirectoryServices命名空间 DirectoryEntry类与DirectorySearcher类一起是最重要的。

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.

使用AD语言时,一切都是 DirectoryEntry 。话虽如此,我的应用程序需要管理用户,组和组织单位(OU)。这些对象都是AD条目。然后,这对我来说是 GenericTypes

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.

我想完成的是:

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. 活动目录

  4. Windows窗体

  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:

是否存在 C#where(通用类型约束)关键字,或任何最佳做法?

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

推荐答案

就像这样:

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 })

这篇关于通用约束关键字在C#的任何VBNET等效项中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆