我正在將C#應用程序轉換爲VB,但對於一些產生的錯誤並不確定。將c#應用程序轉換爲VB
在C#我有─
var quotesInvoker = new QuotesInvoker(new[] { "EUR=X", "JPY=X" });
它轉換到 -
Dim quotesInvoker = New Reuters_Downloader.HttpSample.Invokers.QuotesInvoker(New() {"EUR=X", "JPY=X"})
但是新的()具有 '預期的類型' 如果我修改代碼來讀取的錯誤 -
Dim quotesInvoker = New Reuters_Downloader.HttpSample.Invokers.QuotesInvoker(CType(New Object() {"EUR=X", "JPY=X"}, String()))
問題消失了,但我不知道這是否是一個好的解決方案。任何意見?
藉助於此,我們有這個C#QuotesInvoker代碼 -
public class QuotesInvoker : IInvoker<RetrieveItem_Request_3, ItemResponse_Short_Or_Full[]>
{
private readonly string[] rics;
public QuotesInvoker(string[] rics)
{
this.rics = rics;
}
public ItemResponse_Short_Or_Full[] Invoke(AuthorizationType authorization, RetrieveItem_Request_3 request)
{
var proxy = new Quotes_1Client();
ItemResponse_Short_Or_Full[] response;
proxy.RetrieveItem_3(null, authorization, request, out response);
return response;
}
public RetrieveItem_Request_3 CreateRequest()
{
var retval = new RetrieveItem_Request_3();
retval.TrimResponse = false;
var request = new ItemRequest_2[1];
var request0 = new ItemRequest_2();
request0.Fields = "";
var keys = new List<InstrumentKey_2>();
foreach(var ric in rics)
{
keys.Add(new InstrumentKey_2
{
Name = ric,
NameType = "RIC"
});
}
request0.RequestKey = keys.ToArray();
request0.ExpandChains = true;
request0.Scope = Scope.All;
request[0] = request0;
retval.ItemRequest = request;
return retval;
}
}
其轉換爲 -
Public Class QuotesInvoker
Implements IInvoker(Of RetrieveItem_Request_3, ItemResponse_Short_Or_Full())
Private ReadOnly rics As String()
Public Sub New(rics As String())
Me.rics = rics
End Sub
Public Function Invoke(authorization As AuthorizationType, request As RetrieveItem_Request_3) As ItemResponse_Short_Or_Full()
Dim proxy = New Quotes_1Client()
Dim response As ItemResponse_Short_Or_Full() = Nothing
proxy.RetrieveItem_3(Nothing, authorization, request, response)
Return response
End Function
Public Function CreateRequest() As RetrieveItem_Request_3
Dim retval = New RetrieveItem_Request_3()
retval.TrimResponse = False
Dim request = New ItemRequest_2(0) {}
Dim request0 = New ItemRequest_2()
request0.Fields = ""
Dim keys = New List(Of InstrumentKey_2)()
For Each ric In rics
keys.Add(New InstrumentKey_2() With { _
Key .Name = ric, _
Key .NameType = "RIC" _
})
Next
request0.RequestKey = keys.ToArray()
request0.ExpandChains = True
request0.Scope = Scope.All
request(0) = request0
retval.ItemRequest = request
Return retval
End Function
End Class
這在「類 'QuotesInvoker' 2線路產生一個錯誤必須實現「功能的createRequest ()ThomsonReutersKnowledgeDirect.RetrieveItem_Request_3'爲接口'IInvoker(ThomsonReutersKnowledgeDirect.RetrieveItem_Request_3,ThomsonReutersKnowledgeDirect.ItemResponse_Short_Or_Full())'。「
的「無差錯」 Vb的譯名爲「RetrieveItem_Request_3' 是 -
<System.Diagnostics.DebuggerStepThroughAttribute()> _
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")> _
<System.ServiceModel.MessageContractAttribute(IsWrapped:=False)> _
Partial Public Class RetrieveItem_3_RequestMessage
<System.ServiceModel.MessageHeaderAttribute([Namespace]:="http://www.reuters.com/ns/2008/03/01/webservices/rkd/Cache_1")> _
Public CacheRequest As ThomsonReutersKnowledgeDirect.CacheRequest
<System.ServiceModel.MessageHeaderAttribute([Namespace]:="http://www.reuters.com/ns/2006/05/01/webservices/rkd/Common_1")> _
Public Authorization As ThomsonReutersKnowledgeDirect.AuthorizationType
<System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://www.reuters.com/ns/2006/05/01/webservices/rkd/Quotes_1", Order:=0)> _
Public RetrieveItem_Request_3 As ThomsonReutersKnowledgeDirect.RetrieveItem_Request_3
Public Sub New()
End Sub
Public Sub New(CacheRequest As ThomsonReutersKnowledgeDirect.CacheRequest, Authorization As ThomsonReutersKnowledgeDirect.AuthorizationType, RetrieveItem_Request_3 As ThomsonReutersKnowledgeDirect.RetrieveItem_Request_3)
Me.CacheRequest = CacheRequest
Me.Authorization = Authorization
Me.RetrieveItem_Request_3 = RetrieveItem_Request_3
End Sub
End Class
我失去了與這個所以希望得到任何幫助解決所產生的翻譯錯誤 感謝
將c#轉換爲vb?我爲你感到難過,你爲什麼要這樣做?更嚴重的一點是,爲什麼不編輯你的標題以更具體地描述你所問的內容。 –