예제 #1
0
        /// <summary>
        /// Parse the given string as a parking reservation identification.
        /// </summary>
        public static Boolean TryParse(String Text, out ParkingReservation_Id ReservationId)
        {
            #region Initial checks

            if (Text.IsNullOrEmpty())
            {
                ReservationId = default(ParkingReservation_Id);
                return(false);
            }

            #endregion

            try
            {
                ReservationId = default(ParkingReservation_Id);

                var _MatchCollection = ReservationId_RegEx.Matches(Text);

                if (_MatchCollection.Count != 1)
                {
                    return(false);
                }

                ParkingOperator_Id _OperatorId;

                // New format...
                if (ParkingOperator_Id.TryParse(_MatchCollection[0].Groups[1].Value, out _OperatorId))
                {
                    ReservationId = new ParkingReservation_Id(_OperatorId,
                                                              _MatchCollection[0].Groups[2].Value);

                    return(true);
                }

                if (ParkingOperator_Id.TryParse(_MatchCollection[0].Groups[3].Value, out _OperatorId))
                {
                    ReservationId = new ParkingReservation_Id(_OperatorId,
                                                              _MatchCollection[0].Groups[4].Value);

                    return(true);
                }
            }
#pragma warning disable RCS1075  // Avoid empty catch clause that catches System.Exception.
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
            catch (Exception e)
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
#pragma warning restore RCS1075  // Avoid empty catch clause that catches System.Exception.
            { }

            ReservationId = default(ParkingReservation_Id);
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Parse the given string as a parking reservation identification.
        /// </summary>
        /// <param name="Text">A text representation of a parking reservation identification.</param>
        public static ParkingReservation_Id Parse(String Text)
        {
            #region Initial checks

            if (Text.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Text), "The given text representation of a parking reservation identification must not be null or empty!");
            }

            #endregion

            var MatchCollection = ReservationId_RegEx.Matches(Text);

            ParkingOperator_Id _OperatorId;

            if (ParkingOperator_Id.TryParse(MatchCollection[0].Groups[1].Value, out _OperatorId))
            {
                return(new ParkingReservation_Id(_OperatorId,
                                                 MatchCollection[0].Groups[2].Value));
            }

            throw new ArgumentException("Illegal parking reservation identification '" + Text + "'!",
                                        nameof(Text));
        }