0

I want to create a util that will have a method "Call" which will get 3 arguments:

  1. N (int) - number of times to keep invoke the method "M" if failed .
  2. M ( Any type of method) he needs to invoke.
  3. list of arguments x will need to be invoked with.

this method "Call" should be generic that can return any type T.

so if a method Add is:

public int Add(int x,int y)

I can write

int sum = util.Call<int>(2,Add,5,4);

so method 'Add' of 5,4 will be invoked 2 times if first call throw an exception.

Haddar Macdasi
  • 3,477
  • 8
  • 37
  • 59
  • 1
    1. If the method should support "Any" signature, it'll need to use `dynamic` or `Reflection` is some way. 2. If the method throws `exception` is there a valid point in calling the same method again with same parameters? – Arghya C Dec 12 '15 at 12:41
  • 1 . could you reply with an example for dynamic or reflection ? 2. the point is I will cal methods invoking rest services and some times it will trigger timeout and a second call with a delay will work. (in a time the server is down and I want to continue calling it) – Haddar Macdasi Dec 12 '15 at 12:47
  • Do the arguments need to change for each invoke or will they remain the same? – CSharpie Dec 12 '15 at 12:49
  • _"Please write the code for me"_ is usually not a good Stack Overflow question. Share your research and your progress, even if that doesn't work. Anyway see [C# cleanest way to write retry logic?](http://stackoverflow.com/questions/1563191/c-sharp-cleanest-way-to-write-retry-logic). – CodeCaster Dec 12 '15 at 12:51
  • This can be easily done using Lambdas and Func – CSharpie Dec 12 '15 at 12:51
  • Your `Call` method takes four arguments, not three... – 404 Dec 12 '15 at 12:52

0 Answers0