Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. namespace GCop.Test.Code.TimeSpanFromAnalyzer
  2. {
  3. using System;
  4.  
  5. class ShouldUseTimeSpanExtensions
  6. {
  7. public TimeSpan Span => TimeSpan.FromSeconds(10);
  8.  
  9. public TimeSpan DoubleSpan => TimeSpan.FromSeconds(0.5);
  10.  
  11.  
  12. public void Test()
  13. {
  14. TimeSpan.FromSeconds(5);
  15. TimeSpan.FromDays(5);
  16. TimeSpan.FromHours(5);
  17. TimeSpan.FromMilliseconds(5);
  18. TimeSpan.FromMinutes(5);
  19. TimeSpan.FromTicks(5);
  20. MyCustomTimeSpan.FromSeconds(5);
  21.  
  22. int i = 10;
  23. TimeSpan.FromSeconds(i);
  24. TimeSpan.FromDays(i);
  25. TimeSpan.FromHours(i);
  26. TimeSpan.FromMilliseconds(i);
  27. TimeSpan.FromMinutes(i);
  28. TimeSpan.FromTicks(i);
  29. }
  30. }
  31.  
  32. public class MyCustomTimeSpan
  33. {
  34. public static TimeSpan FromSeconds(int i) // should have warning to use Extension
  35. {
  36. return TimeSpan.FromSeconds(i);
  37. }
  38.  
  39. public static TimeSpan FromSeconds(double d) // do not check (Doubles dont have the extension)
  40. {
  41. return TimeSpan.FromSeconds(d);
  42. }
  43.  
  44. public static TimeSpan FromTicks(int i = 5) // do not check (Doubles dont have the extension)
  45. {
  46. return TimeSpan.FromTicks(i);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement