我正在将C#中的扩展方法转换为VB.Net,但无法找出对输出设置约束的正确方法。
我当前的C#代码正在使用Dictionary,外观如下:
public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
where TValue : new()
{ }
我看过一些问题,解释了如何在inputs上设置约束,例如here,但是我似乎找不到一个解释如何转换where TValue : new()
的output约束的问题。
我确信这很容易,但是我对VB有点生疏,希望这里的人能从头顶上了解到它。
这是从Telerik的Code Converter中获得的转换:
Module Extensions
<Extension()>
Public Function GetOrCreate(Of TKey, TValue As New)(ByVal dict As IDictionary(Of TKey, TValue), ByVal key As TKey) As TValue
End Function
End Module