private static void InitializeConfiguration() { //parse configuration string dividor = ConfigurationManager.AppSettings.Get("MajorStepsBound"); _taxPrefix = ConfigurationManager.AppSettings.Get("TaxPrefix"); if (dividor == null || _taxPrefix == null) { throw new ConfigurationErrorsException("MajorStepsBound and TaxPrefix keys must exist in the configuration."); } if (UInt32.TryParse(dividor, out MajorStepsBound) != true) { throw new ConfigurationErrorsException("MajorStepsBound's value must be an UInt32 number."); } foreach (string key in ConfigurationManager.AppSettings.AllKeys) { if (key.StartsWith(_taxPrefix)) { _steps++; } } _taxSteps = new TaxStep[_steps]; //allocate a sufficient amount of steps int i = 0; UInt32 lower; UInt32 upper; Byte percent; foreach (string key in ConfigurationManager.AppSettings.AllKeys) //parse each tax step from the configuration { if (key.StartsWith(_taxPrefix)) { String[] parts = key.Substring(_taxPrefix.Length).Split(','); if (parts.Length > 2) { throw new ConfigurationErrorsException("Tax key could contain at most two numbers (lower then higher) separated by comma."); } if (UInt32.TryParse(parts[0], out lower) != true || UInt32.TryParse(parts[1], out upper) != true) { throw new ConfigurationErrorsException("Failed parsing tax lower and upper bound."); } if (Byte.TryParse(ConfigurationManager.AppSettings[key], out percent) != true) { throw new ConfigurationErrorsException(String.Format("Failed parsing tax percent for {0} step.", key)); } _taxSteps[i] = new TaxStep(lower, upper, percent); i++; } } }
public int CompareTo(object obj) { TaxStep other = (TaxStep)obj; return((int)(this.LowerBound - other.LowerBound)); }