Z
zino
I'm trying to pass a delegate as parameter but the code below does not
compile. It display an error: 'AddressOf operand must the name of a
method(without parantheses)'
How can I make it work.
Public Class CacheFactory
Delegate Function myDelegateReport(ByVal myInfoStore As
CrystalDecisions.Enterprise.InfoStore) As
System.Collections.Generic.Dictionary(Of Long, String)
Public Shared Function GetCachedItem(ByVal itemKey As integer, ByVal funct
As myDelegateReport, ByVal myInfoStore As
CrystalDecisions.Enterprise.InfoStore) As System.Web.Caching.Cache
If HttpRuntime.Cache(itemKey) Is Nothing Then
Dim folder As System.Collections.Generic.Dictionary(Of Long, String) =
funct.Invoke(myInfoStore)
HttpRuntime.Cache.Insert(itemKey, folder, Nothing)
End If
Return HttpRuntime.Cache
End Function
end class
I created a utilities class that retrieve/create the cache:
Public Class Utilities
Private Delegate Function myDelegateInfoStore(ByVal myInfoStore As
InfoStore) As Dictionary(Of Long, String)
Private Shared Function GetCachedObject(ByVal paramDelegate As
myDelegateInfoStore, ByVal cacheKey As integer, ByVal myInfoStore As
InfoStore) As IDictionary
Dim myDelegate As New CacheFactory.myDelegateReport(AddressOf paramDelegate)
'error: AddressOf operand must the name of a method
....
end function
Private Shared Function GetFolderId(ByVal myInfoStore As InfoStore, ByVal
folderName As String) As Long
Dim folderList As Dictionary(Of Long, String) = GetCachedObject(AddressOf
GetAllFolders, CacheEnum.report_folders, myInfoStore)
....
End Function
Private Shared Function GetAllFolders(ByVal myInfoStore As InfoStore) As
Dictionary(Of Long, String)
.....
end function
end class
class testDelegate
sub test
dim id as integer= GetFolderId(myInfoStore, "folderName")
end sub
end class
compile. It display an error: 'AddressOf operand must the name of a
method(without parantheses)'
How can I make it work.
Public Class CacheFactory
Delegate Function myDelegateReport(ByVal myInfoStore As
CrystalDecisions.Enterprise.InfoStore) As
System.Collections.Generic.Dictionary(Of Long, String)
Public Shared Function GetCachedItem(ByVal itemKey As integer, ByVal funct
As myDelegateReport, ByVal myInfoStore As
CrystalDecisions.Enterprise.InfoStore) As System.Web.Caching.Cache
If HttpRuntime.Cache(itemKey) Is Nothing Then
Dim folder As System.Collections.Generic.Dictionary(Of Long, String) =
funct.Invoke(myInfoStore)
HttpRuntime.Cache.Insert(itemKey, folder, Nothing)
End If
Return HttpRuntime.Cache
End Function
end class
I created a utilities class that retrieve/create the cache:
Public Class Utilities
Private Delegate Function myDelegateInfoStore(ByVal myInfoStore As
InfoStore) As Dictionary(Of Long, String)
Private Shared Function GetCachedObject(ByVal paramDelegate As
myDelegateInfoStore, ByVal cacheKey As integer, ByVal myInfoStore As
InfoStore) As IDictionary
Dim myDelegate As New CacheFactory.myDelegateReport(AddressOf paramDelegate)
'error: AddressOf operand must the name of a method
....
end function
Private Shared Function GetFolderId(ByVal myInfoStore As InfoStore, ByVal
folderName As String) As Long
Dim folderList As Dictionary(Of Long, String) = GetCachedObject(AddressOf
GetAllFolders, CacheEnum.report_folders, myInfoStore)
....
End Function
Private Shared Function GetAllFolders(ByVal myInfoStore As InfoStore) As
Dictionary(Of Long, String)
.....
end function
end class
class testDelegate
sub test
dim id as integer= GetFolderId(myInfoStore, "folderName")
end sub
end class