Ejemplo n.º 1
0
        public static async Task <IList <object> > InvokeMethodAsync(this IInterface i, string method, params object[] p)
        {
            var m = i.GetMethod(method);

            if (m == null)
            {
                throw new InvalidOperationException($"Method {method} not found on {i.Name}");
            }
            var result = await m.InvokeAsync(new List <object>(p)).AsTask().ConfigureAwait(false);

            if (result.Status.IsFailure)
            {
                throw new AllJoynServiceException(result.Status, i, method + "(...)");
            }
            return(result.Values);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invokes a method on an interface
        /// </summary>
        /// <param name="i">A reference to the interface to invoke</param>
        /// <param name="method">The name of the method to invoke on the interface</param>
        /// <param name="p">Parameters to parse to the method</param>
        /// <returns>The return values from the operation</returns>
        /// <exception cref="InvalidOperationException">Member was not found on the interface.</exception>
        /// <exception cref="AllJoynServiceException">The operation on the interface could not be completed.</exception>
        public static async Task <IList <object> > InvokeMethodAsync(this IInterface i, string method, params object[] p)
        {
            var m = i.GetMethod(method);

            if (m == null)
            {
                throw new InvalidOperationException($"Method {method} not found on {i.Name}");
            }

            var result = await m.InvokeAsync(new List <object>(p)).AsTask().ConfigureAwait(false);

            if (result.Status.IsFailure)
            {
                string plist = (p == null) ? string.Empty : string.Join(",", p.Select(t => t.GetType().Name));
                throw new AllJoynServiceException(result.Status, i, $"{method}({plist})");
            }

            return(result.Values);
        }