In C#, how do I keep certain method calls out of the codebase entirely? -
i'm trying rid of datetime.now
method calls , replace them own getnow()
method, may return fixed date testing purposes.
how can enforce no 1 adds datetime.now
call in future? can use ndepend or stylecop check on continuous integration server?
with ndepend easy write rule:
// <name>forbid datetime.now, use xxx.getnow() instead</name> warn if count > 0 in select methods isdirectlyusing "optional:system.datetime.get_now()"
notice:
- the prefix warn if count > 0 in transforms cql query rule
- the way property referenced through string system.datetime.get_now()
- the prefix optional means "don't emit compilation error if property get_now not found". makes sense since if code doesn't use anymore get_now(), not anymore referenced ndepend analysis.
also, generate original query...
select methods isdirectlyusing "optional:system.datetime.get_now()"
...just right-click datetime.get_now() , choose select methods ... directly using me
Comments
Post a Comment