Vb.net 如何在VB中实现IDictionary(TKey,TValue的)?

Vb.net 如何在VB中实现IDictionary(TKey,TValue的)?,vb.net,generics,collections,interface,Vb.net,Generics,Collections,Interface,我想创建IDictionary(of TKey,TValue)接口的实现,以提供一些包装器功能 Public Class ExtendedDictionary(Of TKey, TValue) Implements IDictionary(Of TKey, TValue) Private _Dictionary As Dictionary(Of TKey, TValue) Public Sub Add(ByVal key As TKey, ByVal value As

我想创建IDictionary(of TKey,TValue)接口的实现,以提供一些包装器功能

Public Class ExtendedDictionary(Of TKey, TValue)
    Implements IDictionary(Of TKey, TValue)

    Private _Dictionary As Dictionary(Of TKey, TValue)

    Public Sub Add(ByVal key As TKey, ByVal value As T) Implements IDictionary(Of TKey, T).Add
    'Impl Here'
    End Sub

End Class
当我这样做时,它会抱怨我没有实现的方法。当我选择实现ICollection方法时,会添加ICollection,但随后会得到一整堆错误。他们中的一些人抱怨具有相同签名的方法。例如:

Public ReadOnly Property IsReadOnly() As Boolean Implements ICollection(Of KeyValuePair(Of TKey, T)).IsReadOnly
        Get
            Return IsReadOnly
        End Get
    End Property
所以我认为这个错误很容易纠正。只需更改方法的名称,因为我们会告诉它实现了哪个方法,所以名称应该无关紧要。所以我把它改成了只舔的东西。更难的问题如下:

    ReadOnly Public Property Count() As Integer Implements ICollection(Of T).Count
        Get
            Return Count
        End Get
    End Property

错误是接口的System.Collections.Generic.ICollection(Of T)未由此类实现。我不知道该怎么处理这个错误。我甚至都不太明白。我交易将(T的)更改为(T的)值,但这没有帮助。

正确的声明是:

  Public ReadOnly Property Count() As Integer Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of TKey, TValue)).Count
    Get
      ' implementation here...
    End Get
  End Property
IntelliSense可以帮助您正确地获取这些声明,但它非常脆弱。首先写下以下内容:

Public Class ExtendedDictionary(Of TKey, TValue)
End Class
向上移动光标并插入此行:

Implements IDictionary(Of TKey, TValue)
当您在最后一步后按Enter键时,IDE将自动插入所有必需的方法和属性