2013-03-07 13 views
6

Ho usato uno strumento per convertire C# in VB. Quando eseguo il programma in VB, viene visualizzato il seguente errore:Serve aiuto per convertire C# in VB

Events cannot be declared with a delegate type that has a return type.

Come si corregge questo codice?

C#:

using System; 
[assembly: CLSCompliant(true)] 

namespace Link.API 
{ 
    public delegate decimal DecimalStringDelegate(string s); 
    public delegate long OrderDelegateStatus(Order o); 
    public delegate void LongDelegate(long val); 
} 

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace Link.API 
{ 
    public interface TLServer 
    { 
    event LongDelegate newOrderCancelRequest; 
    event OrderDelegateStatus newSendOrderRequest; 
    string ClientName(int clientnum); 
    bool SymbolSubscribed(string sym); 

    Basket AllClientBasket { get; } 
    } 
} 

VB.NET:

Imports System.Text 
Imports System.Collections.Generic 
Imports System 
<Assembly: CLSCompliant(True)> 

Namespace Link.API 
    Public Delegate Function DecimalStringDelegate(ByVal s As String) As Decimal 
    Public Delegate Function OrderDelegateStatus(ByVal o As Order) As Long 
    Public Delegate Sub LongDelegate(ByVal val As Long) 
End Namespace 

Namespace Link.API 
    Public Interface Server 
    Event newOrderCancelRequest As LongDelegate 
    Event newSendOrderRequest As OrderDelegateStatus 
    Function ClientName(ByVal clientnum As Integer) As String 
    Function SymbolSubscribed(ByVal sym As String) As Boolean 
    ReadOnly Property AllClientBasket() As Basket 
    End Interface 
End Namespace 
+1

Se posso chiedere, _perché_ stai convertendo questo codice? C# e VB.NET suonano bene insieme, puoi combinare classi .NET, importarle l'una dall'altra ecc. –

+1

@BenjaminGruenbaum "puoi combinare le classi .NET" non in un progetto - dovrebbe essere un assembly separato. –

+0

Ho trovato [questo post] (http://www.vbforums.com/showthread.php?597718-Having-problem-converting-delegate-from-C-to-VB), spero che aiuti. –

risposta

6

Come l'errore allude, VB non supporta gli eventi che utilizzano un delegato con un tipo di ritorno. Quindi non è possibile convertire il codice direttamente. Una soluzione potrebbe essere quella di cambiare il delegato di utilizzare un parametro ByRef invece:

Public Delegate Sub DecimalStringDelegate(ByVal s As String, ByRef retVal as Decimal) 
Public Delegate Sub OrderDelegateStatus(ByVal o As Order, ByRef retVal As Long) 
+0

grazie a tutti per l'input – user1905155

Problemi correlati