views:

70

answers:

2

Is there a way to tell to VS2005 to get compiler error when using "some defined" method?

It probably sounds strange, but I do not want to compile when using Decimal.Round().

Reason:
CF does not round by "awayfromzero", so I created a method to do this job. But sometimes I (and team) forget that is not to use Decimal.Round. So I'd like to get a compiler error when using it.

+3  A: 

Unfortunately, you cannot do this with the compiler.

FXCop, however, could easily be set up with a rule about it.

Randolpho
+3  A: 

I am not aware of any way to do this, but you could create an extension method of the Decimal class. Something like Decimal.RoundAwayFromZero(). That might be easier to remember since you will see it in Intellisense.

Carl
Not a bad idea. +1
Randolpho
+1 for an elegant solution, I wish we weren't targetting .NET CF 2.0 :( I'm running into the same issue as OP alot and it's tricky not to let it slip through tests
deltreme