Exemplo n.º 1
0
        /// <summary>
        /// Converts the string representation of a four-bit number to its <see cref="FourBitNumber"/> equivalent.
        /// </summary>
        /// <param name="input">A string containing a number to convert.</param>
        /// <returns>A <see cref="FourBitNumber"/> equivalent to the four-bit number contained in
        /// <paramref name="input"/>.</returns>
        /// <exception cref="ArgumentException"><paramref name="input"/> is null or contains white-spaces only.</exception>
        /// <exception cref="FormatException"><paramref name="input"/> has invalid format.</exception>
        public static FourBitNumber Parse(string input)
        {
            byte byteValue;
            var  parsingResult = ShortByteParser.TryParse(input, Min, Max, out byteValue);

            if (parsingResult.Status == ParsingStatus.Parsed)
            {
                return((FourBitNumber)byteValue);
            }

            throw parsingResult.Exception;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the string representation of a four-bit number to its <see cref="FourBitNumber"/> equivalent.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="input">A string containing a number to convert.</param>
        /// <param name="fourBitNumber">When this method returns, contains the <see cref="FourBitNumber"/>
        /// equivalent of the four-bit number contained in <paramref name="input"/>, if the conversion succeeded,
        /// or zero if the conversion failed. The conversion fails if the <paramref name="input"/> is null or
        /// <see cref="string.Empty"/>, or is not of the correct format. This parameter is passed uninitialized;
        /// any value originally supplied in result will be overwritten.</param>
        /// <returns>true if <paramref name="input"/> was converted successfully; otherwise, false.</returns>
        public static bool TryParse(string input, out FourBitNumber fourBitNumber)
        {
            fourBitNumber = default(FourBitNumber);

            byte byteValue;
            var  parsed = ShortByteParser.TryParse(input, Min, Max, out byteValue).Status == ParsingStatus.Parsed;

            if (parsed)
            {
                fourBitNumber = (FourBitNumber)byteValue;
            }

            return(parsed);
        }
Exemplo n.º 3
0
        public static bool TryParse(string input, out SevenBitNumber result)
        {
            result = default(SevenBitNumber);

            byte byteValue;
            var  parsed = ShortByteParser.TryParse(input, Min, Max, out byteValue).Status == ParsingStatus.Parsed;

            if (parsed)
            {
                result = (SevenBitNumber)byteValue;
            }

            return(parsed);
        }