Reputation: 61
Hey i've tried all the online code converters but none of them work on this. Can someone please explain to me how to transform this sniped it to vb.net?
yahoo.OnBuddyAddYouRequest += delegate(object sender, string buddy, string requestMessage, ref bool bAccept)
{
object[] inVar = { sender, buddy, requestMessage,bAccept };
this.Invoke(new OnBuddyAddYouRequestYahooEventHandler(OnBuddyAddYouRequest), inVar);
bAccept = (bool)inVar[3];
};
Upvotes: 0
Views: 116
Reputation: 66604
Change the inner code to a separate method:
private void buddyAddYouRequest(object sender, string buddy,
string requestMessage, ref bool bAccept)
{
object[] inVar = { sender, buddy, requestMessage, bAccept };
this.Invoke(new OnBuddyAddYouRequestYahooEventHandler(OnBuddyAddYouRequest), inVar);
bAccept = (bool)inVar[3];
}
and then change the line you quoted into this:
yahoo.OnBuddyAddYouRequest += buddyAddYouRequest;
Then you can run this through a code converter to convert it to VB.NET.
However, I should point out that the code makes no sense. It seems to invoke an existing method, OnBuddyAddYouRequest
, but in an unnecessarily roundabout way. I realise that the author may be trying to overcome multi-threading issues; in that case, you can write it much more simply (and type-safe) like this:
private void buddyAddYouRequest(object sender, string buddy,
string requestMessage, ref bool bAccept)
{
bool bAcceptCopy = bAccept;
this.Invoke(new Action(() => OnBuddyAddYouRequest(sender, buddy,
requestMessage, ref bAcceptCopy)));
bAccept = bAcceptCopy;
}
// ...
yahoo.OnBuddyAddYouRequest += buddyAddYouRequest;
Upvotes: 2