123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using System;
- namespace Wayne.ForecourtControl
- {
- /// <summary>
- /// Price group stucture. Contains an underlying int between 0 and 11.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")]
- public struct PriceGroup
- {
- #region Fields
- int value;
- #endregion
- #region Construction
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String)")]
- private PriceGroup(int newValue, bool forceValue)
- {
- if ((newValue >= MinValue) && (newValue <= MaxValue) || forceValue)
- {
- value = newValue;
- }
- else
- throw new ArgumentException(
- "Price group must be within the bounds " +
- MinValue.ToString(System.Globalization.CultureInfo.InvariantCulture) +
- "-" +
- MaxValue.ToString(System.Globalization.CultureInfo.InvariantCulture
- ));
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="newValue"></param>
- public PriceGroup(int newValue)
- : this(newValue, false)
- {
- }
- #endregion
- #region Methods
- /// <summary>
- /// Equality comparer.
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2231:OverloadOperatorEqualsOnOverridingValueTypeEquals")]
- public override bool Equals(object obj)
- {
- if (obj is PriceGroup)
- return (int)((PriceGroup)obj) == this.value;
- else
- return false;
- }
- /// <summary>
- /// Hash Code generator.
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return value.GetHashCode();
- }
-
- #endregion
- #region Debug methods
- /// <summary>
- /// Presents the class as a string.
- /// </summary>
- /// <returns></returns>
- public string ToString(string format, IFormatProvider provider)
- {
- string extraText = " ";
- switch (value)
- {
- case -1: extraText = " Unknown"; break;
- case 0: extraText = " FullService"; break;
- case 1: extraText = " PayInKiosk"; break;
- case 2: extraText = " OptCard"; break;
- case 3: extraText = " OptCash"; break;
- }
- return value.ToString(format, provider) + extraText;
- }
- /// <summary>
- /// Presents the class as a string using the specified culture-specific format information.
- /// </summary>
- /// <returns></returns>
- public string ToString(IFormatProvider provider)
- {
- return ToString("", provider);
- }
- /// <summary>
- /// Presents the class as a string using a format string.
- /// </summary>
- /// <returns></returns>
- public string ToString(string format)
- {
- return ToString(format, System.Globalization.CultureInfo.InvariantCulture);
- }
- /// <summary>
- /// Presents the class as a string using a format string and the specified culture-specific format information.
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return ToString("", System.Globalization.CultureInfo.InvariantCulture);
- }
- #endregion
- #region Conversions
- /// <summary>
- ///
- /// </summary>
- /// <param name="thePriceGroup"></param>
- /// <returns></returns>
- public static implicit operator int(PriceGroup thePriceGroup)
- {
- return thePriceGroup.value;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="priceGroupId"></param>
- /// <returns></returns>
- public static implicit operator PriceGroup(int priceGroupId)
- {
- return new PriceGroup(priceGroupId);
- }
- #endregion
- #region Public constants
- /// <summary>
- ///
- /// </summary>
- public const int MinValue = 0;
- /// <summary>
- ///
- /// </summary>
- public const int MaxValue = 11;
- /// <summary>
- ///
- /// </summary>
- public static readonly PriceGroup FullService = 0;
- /// <summary>
- ///
- /// </summary>
- public static readonly PriceGroup PayInKiosk = 1;
- /// <summary>
- ///
- /// </summary>
- public static readonly PriceGroup OptCash = 2;
- /// <summary>
- ///
- /// </summary>
- public static readonly PriceGroup OptCard = 3;
- /// <summary>
- ///
- /// </summary>
- public static readonly PriceGroup Unknown = new PriceGroup(-1, true);
- #endregion
- }
- }
|