ElektroStudios
ElektroStudios

Reputation: 20474

Property with Type parameter?

It is possible in VB.Net to design a readonly property which accepts a type paramater like this pseudo-example?:

Public ReadOnly Property Resources(of T) As IEnumerable(Of T)
    Get ' Returns the value of a function.
        Return Me.GetResources(Of T)()
    End Get
End Property

And also an overload like this?:

Public ReadOnly Property Resources As IEnumerable(Of Object)
    Get ' Returns the value of a function.
        Return Me.GetResources(Of Object)()
    End Get
End Property

PS: The definition of my Class is not generic.

Upvotes: 0

Views: 362

Answers (1)

FastAl
FastAl

Reputation: 6279

Frustratingly, .Net doesn't allow it. It gives the error we find here:

https://learn.microsoft.com/en-us/dotnet/visual-basic/misc/bc32065

Accessed 10/2017:

Type parameters cannot be specified on this declaration

A programming element is declared with a type parameter list, but the programming element is not eligible to be a generic type.

Programming elements that are not eligible to be generic include properties, operators, events, and constructors. Declaring any of these elements with a type parameter list results in this error.

Error ID: BC32065

To correct this error

  • Remove the Of keyword and the type parameters from the declaration.

Upvotes: 1

Related Questions