AllowedFuelGrades.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #region --------------- Copyright Dresser Wayne Pignone -------------
  2. /*
  3. * $Log: /Wrk/Support/ForecourtControl/Wrk/ForecourtControl/AllowedFuelGrades.cs $
  4. *
  5. * 2 07-01-05 8:58 roger.månsson
  6. * Moved out fuelgrade out of range exception to separate file. Created an
  7. * interface for COM.
  8. */
  9. #endregion
  10. namespace Wayne.ForecourtControl
  11. {
  12. /// <summary>
  13. /// A collection representing the allowed fuel grades that should be used within the authrorize parameters.
  14. /// </summary>
  15. public sealed class AllowedFuelGrades : Wayne.ForecourtControl.IAllowedFuelGrades
  16. {
  17. #region Fields
  18. bool[] allowedFuelGrades = new bool[Defines.MaxFuelGradeCount];
  19. #endregion
  20. #region Construction
  21. /// <summary>
  22. /// Internal constructor prohibits creation of this class outside the assembly.
  23. /// </summary>
  24. internal AllowedFuelGrades()
  25. {
  26. }
  27. #endregion
  28. #region Indexer
  29. /// <summary>
  30. /// Indexer returning if the fuel grade is allowed.
  31. /// </summary>
  32. /// <param name="index">Fuel grade</param>
  33. /// <returns>True if the fuel grade is allowed, False if it is disallowed.</returns>
  34. /// <exception cref="FuelGradeOutOfRangeException">Thrown if the fuel grade is out of range.</exception>
  35. public bool this[int index]
  36. {
  37. get
  38. {
  39. EvaluateIndex(index);
  40. return allowedFuelGrades[index];
  41. }
  42. set
  43. {
  44. EvaluateIndex(index);
  45. allowedFuelGrades[index] = value;
  46. }
  47. }
  48. #endregion
  49. #region Methods
  50. private void EvaluateIndex(int index)
  51. {
  52. if ((index < 0) || (index >= allowedFuelGrades.Length))
  53. throw new FuelGradeOutOfRangeException(index.ToString(System.Globalization.CultureInfo.InvariantCulture) + " is out of range for fuel grades");
  54. }
  55. #endregion
  56. #region Properties
  57. /// <summary>
  58. /// Indicates the number of fuel grades.
  59. /// </summary>
  60. public int Count
  61. {
  62. get
  63. {
  64. return allowedFuelGrades.Length;
  65. }
  66. }
  67. #endregion
  68. }
  69. }