/// <summary> /// Get translated free values and try to cast them to specified type. /// </summary> /// <typeparam name="T">The destination type that you want each value to cast to.</typeparam> /// <param name="result">The argument parsing result.</param> /// <param name="name">The name of the free value.</param> /// <returns>The translated free values.</returns> /// <exception cref="ArgumentNullException"> /// <para>The <paramref name="result"/> is <c>null</c>.</para> /// <para>-- Or --</para> /// <para>The <paramref name="name"/> is <c>null</c>.</para> /// </exception> /// <exception cref="ArgumentException"> /// The <paramref name="name"/> specified is not defined. /// </exception> /// <exception cref="InvalidOperationException"> /// The <paramref name="result"/> is not a successful one. /// </exception> public static IList <T> GetFreeValue <T>(this ArgsParsingResult result, string name) { if (result == null) { throw new ArgumentNullException(nameof(result)); } IList <object> values = result.GetFreeValue(name); return(values.Cast <T>().ToArray()); }
/// <summary> /// Get first element of translated free values 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="name">The name of the free value.</param> /// <returns>The translated free value.</returns> /// <exception cref="ArgumentNullException"> /// <para>The <paramref name="result"/> is <c>null</c>.</para> /// <para>-- Or --</para> /// <para>The <paramref name="name"/> is <c>null</c>.</para> /// </exception> /// <exception cref="ArgumentException"> /// The <paramref name="name"/> 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="name"/>.</para> /// </exception> public static T GetFirstFreeValue <T>(this ArgsParsingResult result, string name) { if (result == null) { throw new ArgumentNullException(nameof(result)); } IList <object> values = result.GetFreeValue(name); return((T)values.First()); }