code_junkie

What is the cleanest way to write this if..then logic

Nov 13th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. if (!String.IsNullOrEmpty(returnUrl))
  2. {
  3. return Redirect(returnUrl);
  4. }
  5. return RedirectToAction("Open", "ServiceCall");
  6.  
  7. if (!String.IsNullOrEmpty(returnUrl))
  8. {
  9. return Redirect(returnUrl);
  10. }
  11. else
  12. {
  13. return RedirectToAction("Open", "ServiceCall");
  14. }
  15.  
  16. return String.IsNullOrEmpty(returnUrl) ?
  17. RedirectToAction("Open", "ServiceCall") :
  18. Redirect(returnUrl);
  19.  
  20. return String.IsNullOrEmpty(returnUrl)
  21. ? RedirectToAction("Open", "ServiceCall")
  22. : Redirect(returnUrl);
  23.  
  24. if (String.IsNullOrEmpty(returnUrl))
  25. {
  26. return RedirectToAction("Open", "ServiceCall");
  27. }
  28. else
  29. {
  30. return Redirect(returnUrl);
  31. }
  32.  
  33. // Andrew Rollings solution
  34. return String.IsNullOrEmpty(returnUrl) ?
  35. RedirectToAction("Open", "ServiceCall") :
  36. Redirect(returnUrl);
  37.  
  38. if (String.IsNullOrEmpty(returnUrl))
  39. {
  40. return RedirectToAction("Open", "ServiceCall");
  41. }
  42. return Redirect(returnUrl);
  43.  
  44. if (!String.IsNullOrEmpty(returnUrl))
  45. {
  46. result = Redirect(returnUrl);
  47. }
  48. else
  49. {
  50. result = RedirectToAction("Open", "ServiceCall");
  51. }
  52.  
  53. return result;
  54.  
  55. void myfunc()
  56. {
  57. if (!String.IsNullOrEmpty(returnUrl))
  58. {
  59. return Redirect(returnUrl);
  60. }
  61. else
  62. {
  63. return RedirectToAction("Open", "ServiceCall");
  64. }
  65. }
  66.  
  67. void myfunc()
  68. {
  69. // ... maybe some code here ...
  70.  
  71. if(!String.IsNullOrEmpty(returnUrl))
  72. {
  73. return Redirect(returnUrl);
  74. }
  75.  
  76. // ... a bunch of other code ...
  77.  
  78. return RedirectToAction("Open", "ServiceCall");
  79. }
  80.  
  81. if (!String.IsNullOrEmpty(returnUrl))
  82. return Redirect(returnUrl);
  83. else
  84. return RedirectToAction("Open", "ServiceCall");
  85.  
  86. return
  87. string.isNullorEmpty(returnUrl) ?
  88. RedirectToAction("Open", "ServiceCall") :
  89. Redirect(returnUrl);
  90.  
  91. if ( )
  92. {
  93. return ...
  94. }
  95. return
  96.  
  97. if ( )
  98. {
  99. }
  100. else
  101. {
  102. }
  103.  
  104. if ()
  105. {
  106. code ...
  107. }
  108. else
  109. {
  110. code...
  111. }
  112.  
  113. if ( ) {
  114. code ...
  115. } else {
  116. code ...
  117. }
  118.  
  119. if(String.IsNullOrEmpty(returnUrl)) {
  120. return RedirectToAction("Open", "ServiceCall");
  121. }
  122. else{ return Redirect(returnUrl); }
  123.  
  124. if (!String.IsNullOrEmpty(returnUrl))
  125. {
  126. // hooray, we have a URL
  127. return Redirect(returnUrl);
  128. }
  129. else
  130. {
  131. // no url, go to the default place
  132. return RedirectToAction("Open", "ServiceCall");
  133. }
  134.  
  135. if (!String.IsNullOrEmpty(returnUrl))
  136. return Redirect(returnUrl);
  137. return RedirectToAction("Open", "ServiceCall");
Add Comment
Please, Sign In to add comment