简体   繁体   English

VB.Net中的递归泛型类型声明

[英]Recursive Generic Type Declaration in VB.Net

I'm a newbie to VB, and I am having difficulty understanding what the following (legacy code) class declaration actually means: 我是VB的新手,我很难理解以下(旧版代码)类声明的实际含义:

Public MustInherit Class ModelBase(Of T As {ModelBase(Of T, TIdType), New}, TIdType)

Can anyone explain the above? 谁能解释以上内容? There is also a related ModelBaseCollection : 还有一个相关的ModelBaseCollection

Public MustInherit Class ModelBaseCollection(Of TCollection As {ModelBaseCollection(Of TCollection, TModel, TIdType), New}, TModel As {ModelBase(Of TModel, TIdType), New}, TIdType)
Inherits Collection(Of TModel)

I have difficulty understanding the need for the ModelBaseCollection class as the ModelBase class is a generic type. 我很难理解对ModelBaseCollection类的需求,因为ModelBase类是泛型类型。

Given the lack of an answer for over 8 months, the comments referring to the Curiously Recurring Template Pattern have been seen (correctly) as solutions. 鉴于超过8个月没有答案,因此(正确地)将有关“ 好奇地重复使用模板模式”的评论视为解决方案。

Nevertheless, this can be explicitly described: 尽管如此,这可以明确描述:

Public MustInherit

It is publicly accessible and cannot be created directly, but must be inherited to use; 它是可公开访问的,不能直接创建,但必须继承使用。

 Class ModelBase(Of

It is a generic class where the specified classes are: 它是一个通用类,其中指定的类为:

  T As {ModelBase(Of T, TIdType), New},

a creatable class inheriting from this class, and 从该类继承的可创建类,以及

  TIdType)

another type. 另一种类型。

Without seeing the rest of the code, the ModelBaseCollection is just the same sort of construct, being able to refer to creatable versions of (an inherited class of) itself and the corresponding ModelBase . 在没有看到其余代码的情况下, ModelBaseCollection只是一种相同的构造,能够引用其本身(和其继承的类)以及相应的ModelBase可创建版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM