我有以下工作方法:
Private Delegate Function WebMethodDelegate(Of TRequest, TResponse)(ByVal request As TRequest) As TResponse
Private Function CallWebMethod(Of TRequest, TResponse)(ByVal request As TRequest, ByVal theMethodToRun As WebMethodDelegate(Of TRequest, TResponse)) As TResponse
Dim response As TResponse = Nothing
'begin pseudocode
While somtthing is true
response = theMethodToRun.Invoke(Request)
End While
'end pseudocode
End Function
我用(一个丑陋的调用)调用上面的代码:
Dim webMethodDeletgate As New WebMethodDelegate(Of wsLookupServiceProxy.RequestBase, wsLookupServiceProxy.GetSelectedLookupInfoResponseOfTitle)(AddressOf _service.GetAllTitles)
CallWebMethod(Of wsLookupServiceProxy.RequestBase, wsLookupServiceProxy.GetSelectedLookupInfoResponseOfTitle)(request, webMethodDeletgate)
我想过这样做:
Dim requestType As Type = GetType(wsLookupServiceProxy.RequestBase)
Dim responseType As Type = GetType(wsLookupServiceProxy.GetSelectedLookupInfoResponseOfTitle)
Dim webMethodDeletgate As New WebMethodDelegate(Of requestType, responseType)(AddressOf _service.GetAllTitles)
CallWebMethod(Of requestType, responseType)(request, webMethodDeletgate)
但是编译器不喜欢它。
我想知道是否有人可以提供一种更干净的方式来调用方法,而没有非常长的方法调用?
使用
Imports wsLookupServiceProxy
放在class的最上面你可以把它放到
Dim webMethodDeletgate As New WebMethodDelegate(Of RequestBase, GetSelectedLookupInfoResponseOfTitle)(AddressOf _service.GetAllTitles)
CallWebMethod(request, webMethodDeletgate)
您还可以从方法调用中删除(Of TResult, TResponse)
,因为它们可以从webMehtodDelegate
中确定