如何在VB.NET中创建通用属性?

IAm*_*00B 4 vb.net generics properties

我想做这样的事情:

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
Run Code Online (Sandbox Code Playgroud)

基本上,我想要一个可以是任何类型的项目集合.然后,我将能够做到这样的事情:

Dim myPropertyValue as <the type of some value>
if (MyProperty.Contains(<some value>))
    myPropertyValue = CType(MyProperty(<some value>), <the type of some value>)
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?或者有比使用泛型类型更好的方法吗?

Joe*_*oel 8

您可能必须创建一个通用类来执行此操作

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
Run Code Online (Sandbox Code Playgroud)