In C#, how do I keep certain method calls out of the codebase entirely?

后端 未结 6 1091
迷失自我
迷失自我 2021-01-01 23:54

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 t

6条回答
  •  佛祖请我去吃肉
    2021-01-02 00:18

    You could use Moles in your tests to provide your own DateTime.Now when required, without the need to modify any existing code that calls it.

    Another option might be to modify the assembly after compilation to call something else. (Perhaps, use Mono.Cecil to rewrite the IL, and add a command to the post-build in VS to run it.)

    You could perhaps grab the Mono source and build yourself a custom mscorlib with the function removed.

提交回复
热议问题