/// <summary> /// Get first translated option value in the option list. And try to cast it to specified /// type. /// </summary> /// <typeparam name="T">The destination type that you want the value to cast to.</typeparam> /// <param name="result">The argument parsing result.</param> /// <param name="option">The full form or the abbreviation form of the option.</param> /// <returns>The first value to the option.</returns> /// <exception cref="ArgumentNullException"> /// <para>The <paramref name="result"/> is <c>null</c>.</para> /// <para>-- Or --</para> /// <para>The <paramref name="option"/> is <c>null</c>.</para> /// </exception> /// <exception cref="ArgumentException"> /// The <paramref name="option"/> specified is not defined. /// </exception> /// <exception cref="InvalidOperationException"> /// <para>The <paramref name="result"/> is not a successful one.</para> /// <para>-- Or --</para> /// <para>There is no value for specified <paramref name="option"/>.</para> /// </exception> public static T GetFirstOptionValue <T>(this ArgsParsingResult result, string option) { if (result == null) { throw new ArgumentNullException(nameof(result)); } IList <object> values = result.GetOptionValue(option); return((T)values.First()); }
/// <summary> /// Get translated option values and try to cast them to specified type. /// </summary> /// <param name="result">The argument parsing result.</param> /// <param name="option">The full form or the abbreviation form of the option.</param> /// <typeparam name="T">The destination type that you want each element to cast to</typeparam> /// <returns>The values to the option.</returns> /// <exception cref="ArgumentNullException"> /// <para>The <paramref name="result"/> is <c>null</c>.</para> /// <para>-- Or --</para> /// <para>The <paramref name="option"/> is <c>null</c>.</para> /// </exception> /// <exception cref="ArgumentException"> /// The <paramref name="option"/> specified is not defined. /// </exception> /// <exception cref="InvalidOperationException"> /// The <paramref name="result"/> is not a successful one. /// </exception> public static IList <T> GetOptionValue <T>(this ArgsParsingResult result, string option) { if (result == null) { throw new ArgumentNullException(nameof(result)); } IList <object> values = result.GetOptionValue(option); return(values.Cast <T>().ToArray()); }