子委托的VB lambda表达式

时间:2010-11-29 11:43:37

标签: vb.net

有代码:

Private Sub InsertItemInCache(Of T)(ByVal item As CachedItem(Of T), ByVal dependency As AggregateCacheDependency, _
 ByVal key As String, ByVal updateCallBack As CacheItemUpdateCallback)

CacheItemUpdateCallback的签名是:

Sub CacheItemUpdateCallback(ByVal key As String, ByVal reason As CacheItemUpdateReason, _
     ByRef expensiveObject As Object, ByRef dependency As CacheDependency, ByRef absoluteExpiration As Date, _
     ByRef slidingExpiration As TimeSpan)

我想使用lamba表达式调用InsertItemInCache函数。 此代码未编译:

InsertItemInCache(cachedItem, dependency, key, Function(k, r, e, d, a, s) CacheItemUpdateCallback(k, r, e, d, a, s))

它表示表达式不会产生值

如果我将 Sub CacheItemUpdateCallback 更改为功能CacheItemUpdateCallback 它也没有编译并说嵌套函数没有与委托'委托Sub CacheItemUpdateCallback(键作为字符串,作为System.Web.Caching.CacheItemUpdateReason,ByRef expensiveObject作为对象,ByRef依赖作为System.Web)相同的签名.Caching.CacheDependency,ByRef absoluteExpiration As Date,ByRef slidingExpiration As System.TimeSpan)'

任何人都可以帮我通过lambda表达式调用此方法吗?我希望将来使用闭包并以这种方式调用此函数:

InsertItemInCache(cachedItem, dependency, key, Function(k, r, e, d, a, s) CacheItemUpdateCallbackNew(k, r, e, d, a, s, additionalParameter1, additionalParameter2, additionalParameter3))

1 个答案:

答案 0 :(得分:2)

这个怎么样?

InsertItemInCache(cachedItem, dependency, key, _
  Sub(k, r, e, d, a, s) CacheItemUpdateCallback(k, r, e, d, a, s)) 

我认为这只适用于VB.Net 2010.据我所知,早期版本不支持Sub lambdas。