I am still trying to translate stuff from VB to C# and my latest problem involves Events. In the original Event file I have,
Public Event CommEvent As CommEventHandler
Public Delegate Sub CommEventHandler(ByVal source As Rs232, ByVal Mask As EventMasks)
Then call to the above,
Protected Sub OnCommEventReceived(ByVal source As Rs232, ByVal mask As EventMasks)
Dim del As CommEventHandler = Me.CommEventEvent
If (Not del Is Nothing) Then
Dim SafeInvoker As ISynchronizeInvoke = Nothing
Try
SafeInvoker = DirectCast(del.Target, ISynchronizeInvoke)
Catch
End Try
Try
If (Not SafeInvoker Is Nothing) Then
SafeInvoker.Invoke(del, New Object() {source, mask})
Else
del.Invoke(source, mask)
End If
Catch
'!!! TO-DO
End Try
End If
End Sub
Now if I use the VB to C# converter on the above, I get quite nicely,
public event CommEventHandler CommEvent;
public delegate void CommEventHandler(Rs232 source, EventMasks Mask);
And,
protected void OnCommEventReceived(Rs232 source, EventMasks mask)
{
CommEventHandler del = this.CommEventEvent;
if (((del != null))) {
ISynchronizeInvoke SafeInvoker = null;
try {
SafeInvoker = (ISynchronizeInvoke)del.Target;
} catch {
}
try {
if (((SafeInvoker != null))) {
SafeInvoker.Invoke(del, new object[] { source, mask });
} else {
del.Invoke(source, mask);
}
} catch {
//!!! TO-DO
}
}
}
My problem is the CommEventEvent. There is no definition of this in the C# file yet it is in the original VB file and further, the code translator quite happily translates it.
Where does this come from please and how can I get it to work in the C# file?
It looks to me like this is simply referring to CommEvent
:
CommEventHandler del = this.CommEvent;
I don't know why VB.NET let you refer to this as CommEventEvent
. It could be one of those language shortcuts like how you can omit the word Attribute
from the end of custom attributes or something.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.