Example #1
0
        /// <summary>
        /// Return a text-representation of this object.
        /// </summary>
        public override String ToString()

        => String.Concat(Periods.AggregateWith(", "),
                         " -> ",
                         On.AsString(),
                         UnstructuredText.IsNotNullOrEmpty()
                                 ? "; " + UnstructuredText
                                 : "");
Example #2
0
        /// <summary>
        /// Compares two opening times for equality.
        /// </summary>
        /// <param name="OpeningTimes">An opening time to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(OpeningTime OpeningTimes)

        => Periods.Count().Equals(OpeningTimes.Periods.Count()) &&
        Periods.All(period => OpeningTimes.Periods.Contains(period)) &&

        On.Equals(OpeningTimes.On) &&

        ((!UnstructuredText.IsNullOrEmpty() && !OpeningTimes.UnstructuredText.IsNullOrEmpty()) ||
         (UnstructuredText.IsNullOrEmpty() && OpeningTimes.UnstructuredText.IsNullOrEmpty() && UnstructuredText.Equals(OpeningTimes.UnstructuredText)));
Example #3
0
        /// <summary>
        /// Return the hash code of this object.
        /// </summary>
        /// <returns>The hash code of this object.</returns>
        public override Int32 GetHashCode()
        {
            unchecked
            {
                return(Periods.Aggregate(0, (hashCode, period) => hashCode ^ period.GetHashCode()) ^
                       On.GetHashCode() * 3 ^

                       (UnstructuredText.IsNullOrEmpty()
                           ? UnstructuredText.GetHashCode()
                           : 0));
            }
        }
Example #4
0
        /// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        /// <param name="CustomOpeningTimesSerializer">A delegate to serialize custom opening time JSON objects.</param>
        public JObject ToJSON(CustomJObjectSerializerDelegate <OpeningTime> CustomOpeningTimesSerializer = null)
        {
            var JSON = JSONObject.Create(

                Periods.SafeAny()
                               ? new JProperty("Period", new JArray(Periods.Select(period => period.ToJSON())))
                               : null,

                new JProperty("on", On.AsString()),

                UnstructuredText.IsNotNullOrEmpty()
                               ? new JProperty("unstructuredOpeningTime", UnstructuredText)
                               : null

                );

            return(CustomOpeningTimesSerializer != null
                       ? CustomOpeningTimesSerializer(this, JSON)
                       : JSON);
        }