I want to use the Money pattern to decrease the likelihood of mistakes that incur using raw numbers such as decimal, etc.
Some parts of the system use int64, representing money in minor units i.e. 12345¢. I want to make it explicit that money is always in major units i.e. $123.45, to prevent the disastrous consequences of accidentally using $12345.
The problem is that decimal is implicitly converted from a whole range of numbers including int64. Of course, I could easily create constructors for every number type and throw errors, but this only works runtime.
public Money(decimal amount, Currency currency)
{
// OK
}
public Money(long amount, Currency currency)
{
throw new Exception(...);
}
Ideally I want to prevent compilation. How can this be achieved?