I’m trying to get rid of all DateTime.Now method calls and replace them with my own GetNow() method, which may sometimes return a fixed date for testing purposes.
How can I enforce that no one adds a DateTime.Now call in the future? Can I use NDepend or StyleCop to check this on my continuous integration server?
With NDepend it is very easy to write this rule:
Notice:
Also, to generate the original query…
…just right-click DateTime.get_Now() and choose Select methods … that are directly using me