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

enter image description here


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -