Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 有没有办法使泛型委托的使用更简单?_.net_Vb.net_Delegates - Fatal编程技术网

.net 有没有办法使泛型委托的使用更简单?

.net 有没有办法使泛型委托的使用更简单?,.net,vb.net,delegates,.net,Vb.net,Delegates,我有以下有效的方法: 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 TRe

我有以下有效的方法:

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 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
在你班上的第一名,你可以把这件事写下来

Dim webMethodDeletgate As New WebMethodDelegate(Of RequestBase, GetSelectedLookupInfoResponseOfTitle)(AddressOf _service.GetAllTitles)
CallWebMethod(request, webMethodDeletgate)

您还可以从方法调用中删除
(TResult,treresponse)
,因为它们可以从
webmehtedelegate

中确定。您是否关心
CallWebMethod
webMethodDelegate
谢谢,但我无法实现这一点。wsLookupServiceProxy是一个web服务,我不知道如何从WebMethodDelegate确定CallWebMethod类型,请提供一个示例。另外,CallWebMethod并不是返回TRespose类型的对象。我不确定您是否能够将其大大缩短。我使用了完整的名称空间(xxx.xxx.wsLookupServiceProxy),这允许我从中删除wsLookupServiceProxy。
Dim webMethodDeletgate As New WebMethodDelegate(Of RequestBase, GetSelectedLookupInfoResponseOfTitle)(AddressOf _service.GetAllTitles)
CallWebMethod(request, webMethodDeletgate)