DSharpPlus.CommandsNext/CommandsNextExtension.cs
/// <summary>
/// Converts a string to specified type.
/// </summary>
/// <typeparam name="T">Type to convert to.</typeparam>
/// <param name="value">Value to convert.</param>
/// <param name="ctx">Context in which to convert to.</param>
/// <returns>Converted object.</returns>
Converts a string to specified type.
Converts a string to specified type .
public async Task<object> ConvertArgument<T>(string value, CommandContext ctx)
        {
            var t = typeof(T);
            if (!this.ArgumentConverters.ContainsKey(t))
                throw new ArgumentException("There is no converter specified for given type.", nameof(T));
            if (!(this.ArgumentConverters[t] is IArgumentConverter<T> cv))
                throw new ArgumentException("Invalid converter registered for this type.", nameof(T));
            var cvr = await cv.ConvertAsync(value, ctx).ConfigureAwait(false);
            if (!cvr.HasValue)
                throw new ArgumentException("Could not convert specified value to given type.", nameof(value));
            return cvr.Value;
        }
public async Task < object > ConvertArgument < T > ( string value , CommandContext ctx ) { var t = typeof ( T ) ; if ( ! this . ArgumentConverters . ContainsKey ( t ) ) throw new ArgumentException ( " " , nameof ( T ) ) ; if ( ! ( this . ArgumentConverters [ t ] is IArgumentConverter < T > cv ) ) throw new ArgumentException ( " " , nameof ( T ) ) ; var cvr = await cv . ConvertAsync ( value , ctx ) . ConfigureAwait ( false ) ; if ( ! cvr . HasValue ) throw new ArgumentException ( " " , nameof ( value ) ) ; return cvr . Value ; }
Converts a string to specified type.
Converts a string to specified type .
None
value
string
Value to convert.
Value to convert .
ctx
CommandContext
Context in which to convert to.
Context in which to convert to .
typeparam
Type to convert to.
Type to convert to .