c# 表达式 lambda 到 vb.net
c# Expression lambda to vb.net
使用转换器(Redgate、Telerik 等)后,我无法将此表达式 c# 转换为 vb.net
if (afterItemRemoved != null)
{
cacheItemPolicy.RemovedCallback = x => afterItemRemoved(
x.CacheItem.Key,
(T)x.CacheItem.Value);
}
我尝试了以下表达式但没有成功 (Reflector 8.5 de RedGate y converter.telerik.com)
If (afterItemRemoved IsNot Nothing) Then
cacheItemPolicy.RemovedCallback = x => afterItemRemoved.Invoke(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T))
End If
If afterItemRemoved IsNot Nothing Then
cacheItemPolicy.RemovedCallback = Function(x) afterItemRemoved(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T))
End If
正在查看 RemovedCallback we can see that the required delegate signature is a void
method (A Sub
in VB.Net) (see CacheEntryRemovedCallback) 的文档。
所以所需的 lambda 表达式必须是 "Sub Lambda" 而不是 "Function lambda"
If afterItemRemoved IsNot Nothing Then
cacheItemPolicy.RemoveCallback =
Sub(x) afterItemRemoved(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T))
End If
使用转换器(Redgate、Telerik 等)后,我无法将此表达式 c# 转换为 vb.net
if (afterItemRemoved != null)
{
cacheItemPolicy.RemovedCallback = x => afterItemRemoved(
x.CacheItem.Key,
(T)x.CacheItem.Value);
}
我尝试了以下表达式但没有成功 (Reflector 8.5 de RedGate y converter.telerik.com)
If (afterItemRemoved IsNot Nothing) Then
cacheItemPolicy.RemovedCallback = x => afterItemRemoved.Invoke(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T))
End If
If afterItemRemoved IsNot Nothing Then
cacheItemPolicy.RemovedCallback = Function(x) afterItemRemoved(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T))
End If
正在查看 RemovedCallback we can see that the required delegate signature is a void
method (A Sub
in VB.Net) (see CacheEntryRemovedCallback) 的文档。
所以所需的 lambda 表达式必须是 "Sub Lambda" 而不是 "Function lambda"
If afterItemRemoved IsNot Nothing Then
cacheItemPolicy.RemoveCallback =
Sub(x) afterItemRemoved(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T))
End If