private IBANCountries()
{
//Load country data from XML file
//<Document>
// <Country>
// <ISOCode>FI</ISOCode>
// <IBANLength>18</IBANLength>
// </Country>
// .
// .
//</Document>
IBANLengthByCountry = new Dictionary<string, int>();
//Country specific IBAN lengths are specified in embedded resource xml file
using (var strm = typeof(IBANCountries).Assembly.GetManifestResourceStream("Affecto.Identifiers.xml.IBANCountryData.xml"))
{
XDocument xml = XDocument.Load(strm);
var countries = xml.Descendants("Country");
foreach (var country in countries)
{
string ISOCode = country.Element("ISOCode").Value;
if (String.IsNullOrWhiteSpace(ISOCode))
throw new ApplicationException("Invalid ISOCode in country element in IBANCountryData xml.");
int length;
var isValidLength = int.TryParse(country.Element("IBANLength").Value, out length);
if (isValidLength && length > 0)
IBANLengthByCountry.Add(ISOCode, length);
else
throw new ApplicationException(string.Format("Invalid IBANLength for country '{0}' in IBANCountryData xml.", ISOCode));
}
strm.Close();
}
}