/// <summary>
    ///     Read InputObject argument dictionary as object
    /// </summary>
    /// <remarks>
    ///     Experimental. This might go away anytime and be replaced with something better.
    /// </remarks>
    /// <typeparam name="T"></typeparam>
    /// <param name="name"></param>
    /// <returns></returns>
    public static T?GetObjectArgument <T>(this IResolverContext context, string name)
        where T : IReadFromObjectDictionary, new()
    {
        var arg = context.GetArgument <IReadOnlyDictionary <string, object> >(name);

        if (arg is null)
        {
            return(default);
Exemple #2
0
        /// <summary>
        ///     Read InputObject argument dictionary as object
        /// </summary>
        /// <remarks>
        ///     Experimental. This might go away anytime and be replaced with something better.
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <returns></returns>
        public static T GetObjectArgument <T>(this IResolverContext context, string name)
            where T : IReadFromObjectDictionary, new()
        {
            var arg = context.GetArgument <IReadOnlyDictionary <string, object> >(name);

            var value = new T();

            value.Read(arg);
            return(value);
        }
        public async ValueTask <IResolverResult> EditMessageAsync(IResolverContext context)
        {
            var id    = context.GetArgument <string>("id");
            var input = context.GetObjectArgument <InputMessage>("message");

            var message = await context.Use <IChat>().EditMessageAsync(
                id,
                input.Content);

            return(Resolve.As(message));
        }
Exemple #4
0
        /// <summary>
        ///     Read InputObject argument dictionary as object
        /// </summary>
        /// <remarks>
        ///     Experimental. This might go away anytime and be replaced with something better.
        /// </remarks>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <returns></returns>
        public static IEnumerable <T> GetObjectArgumentList <T>(this IResolverContext context, string name)
            where T : IReadFromObjectDictionary, new()
        {
            var arg = context.GetArgument <IEnumerable <IReadOnlyDictionary <string, object> > >(name);

            if (arg is null)
            {
                yield break;
            }

            foreach (var item in arg)
            {
                if (item is null)
                {
                    yield return(default(T));

                    continue;
                }

                var value = new T();
                value.Read(item);
                yield return(value);
            }
        }