0

Need Help in converting this to VB.NET

   public void GetCustomers(Action<IEnumerable<Customer>> onSuccess, Action<Exception> onFail)
    {
        Manager.Customers.ExecuteAsync(op =>
              {
                  if (op.CompletedSuccessfully)
                  {
                      if (onSuccess != null) 
                          onSuccess(op.Results);
                  }
                  else
                  {
                      if (onFail != null)
                      {
                          op.MarkErrorAsHandled();
                          onFail(op.Error);
                      }
                  }
              }
           );
    }
2
  • Note, there is no multi line anonymous delegate (lambda) support for VB 9 Commented Jan 2, 2011 at 8:19
  • Am I hallucinating? I do this at work often. Let me go look it up. Commented Jan 2, 2011 at 8:27

1 Answer 1

1

You can do in-line anonymous functions/subs with syntax like:

Manager.Customers.ExecuteAsync( Sub (op)
                                  If op.CompletedSuccessfully Then
                                    ...
                                  Else
                                    ...
                                  EndIf
                                End Sub )

Sometimes things get really flakey when you use it inline, so when that happens I give the local sub/function a name:

Dim SomeFun as Action(Of OpType) = Sub (op)
                                     ...
                                   End Sub

This works well because you can still close over your lexical environment.

This is all from memory - I don't have VS at home (and I try not to troll SO at work). In particular, I'm not sure I have my closing paren in the right place.

MSDN Reference

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the response. But I'm still having overload resolution error.
I've finally found the error on the overloaded method. Thanks for the help
Does VB always generate a new delegate each time inline anonymous methods are used, or can an inline method that doesn't use "Me" (explicitly or implicitly) be kept as a single delegate shared by the class?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.