/// <summary> /// Converts a string to specified type. /// </summary> /// <param name="value">Value to convert.</param> /// <param name="ctx">Context in which to convert to.</param> /// <param name="type">Type to convert to.</param> /// <returns>Converted object.</returns> public static object ConvertArgument(this string value, CommandContext ctx, Type type) { var m = ConvertGeneric.MakeGenericMethod(type); try { return(m.Invoke(null, new object[] { value, ctx })); } catch (TargetInvocationException ex) { throw ex.InnerException; } }
/// <summary> /// Converts a string to specified type. /// </summary> /// <param name="value">Value to convert.</param> /// <param name="ctx">Context in which to convert to.</param> /// <param name="type">Type to convert to.</param> /// <returns>Converted object.</returns> public async Task <object> ConvertArgument(string value, CommandContext ctx, Type type) { var m = ConvertGeneric.MakeGenericMethod(type); try { return(await(m.Invoke(this, new object[] { value, ctx }) as Task <object>).ConfigureAwait(false)); } catch (TargetInvocationException ex) { throw ex.InnerException; } }