fork download
  1. using System;
  2.  
  3. public class RestResponse { }
  4. public class RestResponse<T> : RestResponse { public T Data { get; set; } }
  5.  
  6. public static class Client
  7. {
  8. public static RestResponse Execute()
  9. {
  10. return new RestResponse();
  11. }
  12.  
  13. public static RestResponse<T> Execute<T>()
  14. {
  15. return new RestResponse<T>();
  16. }
  17. }
  18.  
  19. public class Test
  20. {
  21. public static void PerformApiCall(Func<RestResponse> method)
  22. {
  23. PerformRequestWithChecks<RestResponse>(method);
  24. }
  25.  
  26. public static T PerformApiCall<T>(Func<RestResponse<T>> method)
  27. {
  28. var response = PerformRequestWithChecks<RestResponse<T>>(method);
  29. return response.Data;
  30. }
  31.  
  32. private static T PerformRequestWithChecks<T>(Func<T> method) where T : RestResponse
  33. {
  34. var response = method();
  35. // Handle errors...
  36. return response;
  37. }
  38.  
  39. public static void Main()
  40. {
  41. // Notice, returns a value
  42. var data = PerformApiCall(() => Client.Execute<int>());
  43.  
  44. // Notice, is the empty version (has no .Data)
  45. PerformApiCall(() => Client.Execute());
  46. }
  47. }
Success #stdin #stdout 0.01s 34576KB
stdin
Standard input is empty
stdout
Standard output is empty