I am starting to play with extension methods, and I ran into this problem: In the following scenario, I get:
"the extension method has a type constraint that can never be executed"
Public Interface IKeyedObject(Of TKey As IEquatable(Of TKey))
ReadOnly Property InstanceKey() As TKey
End Interface
<Extension()> _
Public Function ToDictionary(Of TKey As IEquatable(Of TKey), tValue As IKeyedObject(Of TKey))(ByVal l As IEnumerable(Of tValue)) As IDictionary(Of TKey, tValue)
'code
End Function
But it works if I replace IKeyedObject (Of k) with IKeyedObject (Of Integer)
<Extension()> _
Public Function ToDictionary(Of TKey As IEquatable(Of TKey), tValue As IKeyedObject(Of TKey))(ByVal l As IEnumerable(Of tValue)) As IDictionary(Of TKey, tValue)
'code
End Function
Am I missing something? in any way can i do what i want here?
Thanks in advance
source
share