I'm trying to write an adapter class that accepts any Dictionary
/KeyValuePair
-ish type as a parameter.
Public Class Adapter(Of TKey As IComparable, TValue, TContainer As {IDictionary, New})
Private Structure Entry
Public Value as TValue
' Some other stuff
End Property
Private _Container As TContainer(Of TKey, Entry) ' <-- how do I make TContainer still parametrizable
Public Sub New()
_Container = New TContainer(Of TKey, Entry) ' <-- TContainer needs to be New-able
End Sub
End Class
Does VB.NET allow this type of nested generic parameter (like template template parameters in C++)? and if so, how do I write the generic parameters to accept one?
Expected Usage
Ideally, I'd want to be able to use it like this:
Dim adapter As Adapter(Of String, String, Dictionary) ' <-- _Container will then be Dictionary(String, Entry(Of String))
Additionally
Additionally, is there a way to implement a constructor that accepts an object of type TContainer(Of TKey, Entry)
.
Public Sub New(ByVal container As TContainer(Of TKey, Entry)) '<-- use existing container
_Container = container
End Sub
The only way I see this happening is by making Entry
public but then I'd have to do something like Adapter(Of String, String, Adapter(WHAT_DO_I_PUT_HERE).Entry
. How can I refer to the inner Entry
class if I can't complete the generic Adapter
signature?