private decimal GetRate(XDocument doc, string isoCode)
{
var ns = doc.Root.GetDefaultNamespace();
var rates = doc.Descendants(ns + "Cube");
var rate = rates.FirstOrDefault(r =>
{
if (r.HasAttributes)
{
var currency = r.Attribute("currency");
if (currency != null && currency.Value.ToUpper() == isoCode)
return true;
}
return false;
});
if (rate == null)
throw new Exception("Unable to find requested rate in ECB: " + isoCode);
return decimal.Parse(rate.Attribute("rate").Value);
}
}