VB.Net 泛型约束等效于 C# where TValue : New()
VB.Net Generics Constraints Equivalent to C# where TValue : New()
我正在努力将 C# 中的扩展方法转换为 VB.Net,但无法找到对输出设置约束的正确方法。
我当前的 C# 代码正在处理字典,如下所示:
public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
where TValue : new()
{ }
我看到了解释如何在 输入 上设置约束的问题,例如 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
我正在努力将 C# 中的扩展方法转换为 VB.Net,但无法找到对输出设置约束的正确方法。
我当前的 C# 代码正在处理字典,如下所示:
public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
where TValue : new()
{ }
我看到了解释如何在 输入 上设置约束的问题,例如 here,但我似乎找不到解释如何转换的问题where TValue : new()
我敢肯定这很容易,但我对 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