如何用VB.NET编写一个通用的属性实例?
- 内容介绍
- 文章标签
- 相关推荐
本文共计258个文字,预计阅读时间需要2分钟。
我想做这样的事情:私有属性 _myCollection 作为接口 IList(Of T) 的公共属性 MyProperty(Of T)()。基本思路是,我想要拥有。
我想做这样的事情:Private _myCollection As IList(Of T) Public Property MyProperty(Of T)() as IList(Of T) Get Return Me._myCollection End Get Set(ByVal value As String) Me._myCollection = value End Set End Property
基本上,我想拥有一系列可能属于任何类型的物品.然后,我将能够做到这样的事情:
Dim myPropertyValue as <the type of some value> if (MyProperty.Contains(<some value>)) myPropertyValue = CType(MyProperty(<some value>), <the type of some value>)
我怎样才能做到这一点?或者有比使用泛型类型更好的方法吗?
您可能必须创建一个通用类来执行此操作Public Class MyClass(Of T) Private _myCollection As IList(Of T) Public Property MyProperty() as IList(Of T) Get Return Me._myCollection End Get Set(ByVal value As String) Me._myCollection = value End Set End Property End Class
本文共计258个文字,预计阅读时间需要2分钟。
我想做这样的事情:私有属性 _myCollection 作为接口 IList(Of T) 的公共属性 MyProperty(Of T)()。基本思路是,我想要拥有。
我想做这样的事情:Private _myCollection As IList(Of T) Public Property MyProperty(Of T)() as IList(Of T) Get Return Me._myCollection End Get Set(ByVal value As String) Me._myCollection = value End Set End Property
基本上,我想拥有一系列可能属于任何类型的物品.然后,我将能够做到这样的事情:
Dim myPropertyValue as <the type of some value> if (MyProperty.Contains(<some value>)) myPropertyValue = CType(MyProperty(<some value>), <the type of some value>)
我怎样才能做到这一点?或者有比使用泛型类型更好的方法吗?
您可能必须创建一个通用类来执行此操作Public Class MyClass(Of T) Private _myCollection As IList(Of T) Public Property MyProperty() as IList(Of T) Get Return Me._myCollection End Get Set(ByVal value As String) Me._myCollection = value End Set End Property End Class

