Avoid compiling when using Decimal.Round() method (C#/CF)
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().
开发者_C百科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.Unfortunately, you cannot do this with the compiler.
FXCop, however, could easily be set up with a rule about it.
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.
精彩评论