将具有委托值的 C# 字典转换为其 VB.NET 等价物
Convert C# dictionary with delegate values to its VB.NET equivalent
我需要一些帮助来理解如何将这种使用委托作为值的字典条目从 C# 翻译成 VB.NET:
using LookupT =
System.Collections.Generic.KeyValuePair<string, System.Func<BBCodeNode, bool, string>>;
public delegate string HtmlRendererCallback(BBCodeNode Node,
bool ThrowOnError,
object LookupTable);
static readonly LookupT[] convertLookup =
new Dictionary<string, HtmlRendererCallback>
{
{ "b", DirectConvert }
}.ToArray();
public static string DirectConvert(BBCodeNode Node,
bool ThrowOnError,
object LookupTable)
{
//...
}
我尝试的是下面的翻译,它不起作用,调试器在字典条目 ( {"b", DirectConvert()}
) 中将函数名称标记为错误,要求我将正确的参数传递给 DirectConvert
功能:
Imports LookupT =
System.Collections.Generic.KeyValuePair(Of String, System.Func(Of BBCodeNode, Boolean, String))
Public Delegate Function HtmlRendererCallback(node As BBCodeNode,
throwOnError As Boolean,
lookupTable As Object) As String
Shared ReadOnly convertLookup As LookupT() =
New Dictionary(Of String, HtmlRendererCallback)() From
{
{"b", DirectConvert()}
}.ToArray()
Public Shared Function DirectConvert(node As BBCodeNode,
throwOnError As Boolean,
lookupTable As Object) As String
' ...
End sub
...但是,在 C# 代码中,如果我没记错的话,它似乎根本没有指定函数的任何参数,所以...让我感到困惑。
你能试试这个吗:
Public Delegate Function HtmlRendererCallback(ByVal node As BBCodeNode, ByVal throwOnError As Boolean, ByVal lookupTable As Object) As String
Shared convertMeth As HtmlRendererCallback = AddressOf DirectConvert
Shared ReadOnly convertLookup As ILookup(Of String, HtmlRendererCallback) = New Dictionary(Of String, HtmlRendererCallback)() From {
{"b", convertMeth},
{"c", convertMeth},
{"d", convertMeth}
}
Public Shared Function DirectConvert(ByVal node As BBCodeNode, ByVal throwOnError As Boolean, ByVal lookupTable As Object) As String
DirectConvert = ""
End Function
我需要一些帮助来理解如何将这种使用委托作为值的字典条目从 C# 翻译成 VB.NET:
using LookupT =
System.Collections.Generic.KeyValuePair<string, System.Func<BBCodeNode, bool, string>>;
public delegate string HtmlRendererCallback(BBCodeNode Node,
bool ThrowOnError,
object LookupTable);
static readonly LookupT[] convertLookup =
new Dictionary<string, HtmlRendererCallback>
{
{ "b", DirectConvert }
}.ToArray();
public static string DirectConvert(BBCodeNode Node,
bool ThrowOnError,
object LookupTable)
{
//...
}
我尝试的是下面的翻译,它不起作用,调试器在字典条目 ( {"b", DirectConvert()}
) 中将函数名称标记为错误,要求我将正确的参数传递给 DirectConvert
功能:
Imports LookupT =
System.Collections.Generic.KeyValuePair(Of String, System.Func(Of BBCodeNode, Boolean, String))
Public Delegate Function HtmlRendererCallback(node As BBCodeNode,
throwOnError As Boolean,
lookupTable As Object) As String
Shared ReadOnly convertLookup As LookupT() =
New Dictionary(Of String, HtmlRendererCallback)() From
{
{"b", DirectConvert()}
}.ToArray()
Public Shared Function DirectConvert(node As BBCodeNode,
throwOnError As Boolean,
lookupTable As Object) As String
' ...
End sub
...但是,在 C# 代码中,如果我没记错的话,它似乎根本没有指定函数的任何参数,所以...让我感到困惑。
你能试试这个吗:
Public Delegate Function HtmlRendererCallback(ByVal node As BBCodeNode, ByVal throwOnError As Boolean, ByVal lookupTable As Object) As String
Shared convertMeth As HtmlRendererCallback = AddressOf DirectConvert
Shared ReadOnly convertLookup As ILookup(Of String, HtmlRendererCallback) = New Dictionary(Of String, HtmlRendererCallback)() From {
{"b", convertMeth},
{"c", convertMeth},
{"d", convertMeth}
}
Public Shared Function DirectConvert(ByVal node As BBCodeNode, ByVal throwOnError As Boolean, ByVal lookupTable As Object) As String
DirectConvert = ""
End Function