1
Vote

Code (re)usability improvements

description

Hello, great work! Found you at CodeProject first, than saw the code here, started using it and found some issues worth mentioning:
 
-- I'd like to persist Money type as a string in a custom format, so it's desirable to know if a given currency code is valid in the system. For this case to work i've introduced a Currency.TryParse(..) method with a semantic similar to that of some standard CLR value types.
 
-- For UI purpose it'd be cool to have a list of all valid currencies, so i've exposed it via static Currency.Currencies property
 
-- Presently, there's no way to know if a given Currency instance represents a valid currency until you try to access any instance property and, possibly, get an InvalidOperationException -- ups, not nice! I've made these properties silently return default values if no matching currency was found. So at least the following snippet won't cause an earthquake: new Currency().IsoNumericCode, but just silently return "0". For the sake of consistency, i've also added Currency.Empty static instance.
 
-- Finally, just to simplify a bit working with a huge source file, i've moved a part of Currency.cs into partial class file.

file attachments

comments

esteewhy wrote May 8, 2009 at 1:24 PM

Ups, also, forgot to tell you: I've also created some helper methods to de/serialise Money to/fro string. Just in case smb. w'd be interested...

wrote May 8, 2009 at 1:24 PM

wrote Feb 13, 2013 at 6:11 PM