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 myDelegateRepor t(ByVal myInfoStore As
CrystalDecision s.Enterprise.In foStore) As
System.Collecti ons.Generic.Dic tionary(Of Long, String)
Public Shared Function GetCachedItem(B yVal itemKey As integer, ByVal funct
As myDelegateRepor t, ByVal myInfoStore As
CrystalDecision s.Enterprise.In foStore) As System.Web.Cach ing.Cache
If HttpRuntime.Cac he(itemKey) Is Nothing Then
Dim folder As System.Collecti ons.Generic.Dic tionary(Of Long, String) =
funct.Invoke(my InfoStore)
HttpRuntime.Cac he.Insert(itemK ey, folder, Nothing)
End If
Return HttpRuntime.Cac he
End Function
end class
I created a utilities class that retrieve/create the cache:
Public Class Utilities
Private Delegate Function myDelegateInfoS tore(ByVal myInfoStore As
InfoStore) As Dictionary(Of Long, String)
Private Shared Function GetCachedObject (ByVal paramDelegate As
myDelegateInfoS tore, ByVal cacheKey As integer, ByVal myInfoStore As
InfoStore) As IDictionary
Dim myDelegate As New CacheFactory.my DelegateReport( AddressOf paramDelegate)
'error: AddressOf operand must the name of a method
....
end function
Private Shared Function GetFolderId(ByV al myInfoStore As InfoStore, ByVal
folderName As String) As Long
Dim folderList As Dictionary(Of Long, String) = GetCachedObject (AddressOf
GetAllFolders, CacheEnum.repor t_folders, myInfoStore)
....
End Function
Private Shared Function GetAllFolders(B yVal myInfoStore As InfoStore) As
Dictionary(Of Long, String)
.....
end function
end class
class testDelegate
sub test
dim id as integer= GetFolderId(myI nfoStore, "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 myDelegateRepor t(ByVal myInfoStore As
CrystalDecision s.Enterprise.In foStore) As
System.Collecti ons.Generic.Dic tionary(Of Long, String)
Public Shared Function GetCachedItem(B yVal itemKey As integer, ByVal funct
As myDelegateRepor t, ByVal myInfoStore As
CrystalDecision s.Enterprise.In foStore) As System.Web.Cach ing.Cache
If HttpRuntime.Cac he(itemKey) Is Nothing Then
Dim folder As System.Collecti ons.Generic.Dic tionary(Of Long, String) =
funct.Invoke(my InfoStore)
HttpRuntime.Cac he.Insert(itemK ey, folder, Nothing)
End If
Return HttpRuntime.Cac he
End Function
end class
I created a utilities class that retrieve/create the cache:
Public Class Utilities
Private Delegate Function myDelegateInfoS tore(ByVal myInfoStore As
InfoStore) As Dictionary(Of Long, String)
Private Shared Function GetCachedObject (ByVal paramDelegate As
myDelegateInfoS tore, ByVal cacheKey As integer, ByVal myInfoStore As
InfoStore) As IDictionary
Dim myDelegate As New CacheFactory.my DelegateReport( AddressOf paramDelegate)
'error: AddressOf operand must the name of a method
....
end function
Private Shared Function GetFolderId(ByV al myInfoStore As InfoStore, ByVal
folderName As String) As Long
Dim folderList As Dictionary(Of Long, String) = GetCachedObject (AddressOf
GetAllFolders, CacheEnum.repor t_folders, myInfoStore)
....
End Function
Private Shared Function GetAllFolders(B yVal myInfoStore As InfoStore) As
Dictionary(Of Long, String)
.....
end function
end class
class testDelegate
sub test
dim id as integer= GetFolderId(myI nfoStore, "folderName ")
end sub
end class
Comment