Exemple #1
0
 /// <summary>
 /// Invokes a method using the await keyword
 /// if the method returns Task,
 /// otherwise synchronously invokes the method.
 /// </summary>
 /// <param name="methodName">Name of the method.</param>
 /// <param name="parameters">
 /// Parameters to pass to method.
 /// </param>
 public async Task CallMethodTryAsync(string methodName, params object[] parameters)
 {
     try
     {
         await MethodCaller.CallMethodTryAsync(this.Instance, methodName, parameters);
     }
     catch (CallMethodException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new CallMethodException(Instance.GetType().Name + "." + methodName + " " + Resources.MethodCallFailed, ex);
     }
 }
Exemple #2
0
//    /// <summary>
//    /// Gets a value indicating whether the specified method
//    /// returns a Task of object.
//    /// </summary>
//    /// <param name="methodName">Name of the method.</param>
//    /// <returns>True if the method returns a Task of object.</returns>
//    public bool IsMethodAsync(string methodName)
//    {
//      var info = this.Instance.GetType().GetMethod(methodName);
//#if NETFX_CORE
//      var isgeneric = info.ReturnType.IsGenericType();
//#else
//     var isgeneric = info.ReturnType.IsGenericType;
//#endif
//      return (info.ReturnType.Equals(typeof(Task)));
//    }

        ///// <summary>
        ///// Uses reflection to dynamically invoke a method,
        ///// throwing an exception if it is not
        ///// implemented on the target object.
        ///// </summary>
        ///// <param name="method">
        ///// Name of the method.
        ///// </param>
        //public async Task CallMethodAsync(string method)
        //{
        //  try
        //  {
        //    await (Task)MethodCaller.CallMethod(this.Instance, method);
        //  }
        //  catch (InvalidCastException ex)
        //  {
        //    throw new NotSupportedException(
        //      string.Format(Resources.TaskOfObjectException, this.Instance.GetType().Name + "." + method),
        //      ex);
        //  }
        //}

        ///// <summary>
        ///// Uses reflection to dynamically invoke a method,
        ///// throwing an exception if it is not
        ///// implemented on the target object.
        ///// </summary>
        ///// <param name="method">
        ///// Name of the method.
        ///// </param>
        ///// <param name="parameters">
        ///// Parameters to pass to method.
        ///// </param>
        //public async Task CallMethodAsync(string method, params object[] parameters)
        //{
        //  try
        //  {
        //    await (Task)MethodCaller.CallMethod(this.Instance, method, parameters);
        //  }
        //  catch (InvalidCastException ex)
        //  {
        //    throw new NotSupportedException(
        //      string.Format(Resources.TaskOfObjectException, this.Instance.GetType().Name + "." + method),
        //      ex);
        //  }
        //}

        /// <summary>
        /// Invokes a method using the await keyword
        /// if the method returns Task,
        /// otherwise synchronously invokes the method.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <returns></returns>
        public async Task CallMethodTryAsync(string methodName)
        {
            try
            {
                await MethodCaller.CallMethodTryAsync(this.Instance, methodName);
            }
            catch (Csla.Reflection.CallMethodException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new Csla.Reflection.CallMethodException(Instance.GetType().Name + "." + methodName + " " + Resources.MethodCallFailed, ex);
            }
        }