A Fix Release for NMoneys


It had to happen. I was counting the minutes, the seconds, the… I had my first feedback (positive or negative) for NMoneys. Yeah, it was sort of negative, but a failure never made me happier.

As a result, I made a quick fix of the issue, which is the version.

What Happened?

I have already ranted pointed out how pesky the System.Enum type is: here and most importantly here. It seems I am oblivious from my own experiences and someone else noticed.

When a default instance of Money is created, as in:

or in:

The values of the fields/properties are initialized to their default values. In the case of the Amount, which if decimal type, it will be initialized to default(decimal) which is 0. In the case of CurrencyIsoCode, being of a derivative of System.Enum, anyone guesses what will be its default(CurrencyIsoCode)?
0 will be.
Is there any currency defined with the zero value?
No, there is not.

The type will be created but as soon as any of the features that make use of the Currency represented by its code (.ToString()…) an exception will be thrown as no currency can be used for that code.

This behavior is a bit disturbing and not immediately obvious so I did something about it by releasing this fix. Now, default instances of Money will have a no-currency CurrencyIsoCode.XXX value.

As always, try it and if you find something that can be improved, contribute to make NMoneys a better library.