0

There is the code:

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

The CacheItemUpdateCallback signature is:

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)

I want to call InsertItemInCache function using lamba expression for this. This code is not compiled:

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

it says Expression does not produce a value

If I change Sub CacheItemUpdateCallback to Function CacheItemUpdateCallback it also is not compiled and says Nested function does not have the same signature as delegate 'Delegate Sub CacheItemUpdateCallback(key As String, reason As System.Web.Caching.CacheItemUpdateReason, ByRef expensiveObject As Object, ByRef dependency As System.Web.Caching.CacheDependency, ByRef absoluteExpiration As Date, ByRef slidingExpiration As System.TimeSpan)'

Can anyone help me to call this method via lambda expression? I want to use closure in the future and call this function in such way:

InsertItemInCache(cachedItem, dependency, key, Function(k, r, e, d, a, s) CacheItemUpdateCallbackNew(k, r, e, d, a, s, additionalParameter1, additionalParameter2, additionalParameter3))
Egor4eg
  • 2,678
  • 1
  • 22
  • 41
  • duplicate of http://stackoverflow.com/questions/4303377/vb-lambda-expression-for-sub-delegate ? – Maslow Apr 25 '11 at 14:27

1 Answers1

1

I'm going to guess this is an older vb.net as vb10 released with VS2010 can handle sub Lambdas, but you also have another problem.

Without concern for future closures... this could just be

InsertItemInCache(cachedItem, dependency, key, AddressOf CacheItemUpdateCallback)

So main issue is a lambda expression cannot directly capture a ref [ByRef in VB] or out parameter from an enclosing method.

Community
  • 1
  • 1
Maslow
  • 18,464
  • 20
  • 106
  • 193