コード例 #1
0
        /// <summary>
        /// Try to parse the given string as an EVSE identification.
        /// </summary>
        /// <param name="Text">A text-representation of an EVSE identification.</param>
        /// <param name="EVSEId">The parsed EVSE identification.</param>
        public static Boolean TryParse(String Text, out EVSE_Id EVSEId)
        {
            #region Initial checks

            if (Text != null)
            {
                Text = Text.Trim();
            }

            if (Text.IsNullOrEmpty())
            {
                EVSEId = default(EVSE_Id);
                return(false);
            }

            #endregion

            try
            {
                var MatchCollection = EVSEId_RegEx.Matches(Text.Trim().ToUpper());

                if (MatchCollection.Count == 1)
                {
                    Operator_Id _EVSEOperatorId;

                    // New format...
                    if (Operator_Id.TryParse(MatchCollection[0].Groups[1].Value, out _EVSEOperatorId))
                    {
                        EVSEId = new EVSE_Id(_EVSEOperatorId,
                                             MatchCollection[0].Groups[2].Value);

                        return(true);
                    }

                    // Old format...
                    if (Operator_Id.TryParse(MatchCollection[0].Groups[3].Value, out _EVSEOperatorId))
                    {
                        EVSEId = new EVSE_Id(_EVSEOperatorId,
                                             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)
            { }
#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.

            EVSEId = default(EVSE_Id);
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Parse the given string as an EVSE identification.
        /// </summary>
        /// <param name="Text">A text-representation of an EVSE identification.</param>
        public static EVSE_Id Parse(String Text)
        {
            #region Initial checks

            if (Text != null)
            {
                Text = Text.Trim();
            }

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

            #endregion

            var MatchCollection = EVSEId_RegEx.Matches(Text);

            if (MatchCollection.Count != 1)
            {
                throw new ArgumentException("Illegal EVSE identification '" + Text + "'!",
                                            nameof(Text));
            }

            Operator_Id _OperatorId;

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

            if (Operator_Id.TryParse(MatchCollection[0].Groups[3].Value, out _OperatorId))
            {
                return(new EVSE_Id(_OperatorId,
                                   MatchCollection[0].Groups[4].Value));
            }


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