예제 #1
0
        /// <summary>
        /// Converts the string representation of a whole note's fraction to its <see cref="MusicalTimeSpan"/>
        /// equivalent.
        /// </summary>
        /// <param name="input">A string containing a time span to convert.</param>
        /// <returns>A <see cref="MusicalTimeSpan"/> equivalent to the time span 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 MusicalTimeSpan Parse(string input)
        {
            MusicalTimeSpan timeSpan;
            var             parsingResult = MusicalTimeSpanParser.TryParse(input, out timeSpan);

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

            throw parsingResult.Exception;
        }
예제 #2
0
 /// <summary>
 /// Converts the string representation of a whole note's fraction to its <see cref="MusicalTimeSpan"/>
 /// equivalent. A return value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="input">A string containing a time span to convert.</param>
 /// <param name="timeSpan">When this method returns, contains the <see cref="MusicalTimeSpan"/>
 /// equivalent of the time span contained in <paramref name="input"/>, if the conversion succeeded, or
 /// null 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 MusicalTimeSpan timeSpan)
 {
     return(MusicalTimeSpanParser.TryParse(input, out timeSpan).Status == ParsingStatus.Parsed);
 }