Example #1
0
        static Task <object> DoInvoke(TypedActor target, MethodInfo method, object[] arguments)
        {
            var result = method.Invoke(target, arguments);

            if (!typeof(Task).IsAssignableFrom(method.ReturnType))
            {
                return(method.ReturnType != typeof(void)
                        ? Task.FromResult(result)
                        : Done);
            }

            return(((Task)result).ContinueWith((task, state) =>
            {
                if (task.Status == TaskStatus.Faulted)
                {
                    Debug.Assert(task.Exception != null);
                    throw task.Exception;
                }

                var returnType = (Type)state;
                var returnsResult = returnType != typeof(Task);

                return returnsResult
                        ? (object)((dynamic)task).Result
                        : (object)null;
            },
                                               method.ReturnType));
        }
Example #2
0
        static Task <object> DoInvoke(TypedActor target, PropertyInfo property, object[] arguments)
        {
            if (arguments.Length == 0)
            {
                return(Task.FromResult(property.GetValue(target)));
            }

            property.SetValue(target, arguments[0]);
            return(Done);
        }
Example #3
0
        static Task <object> DoInvoke(TypedActor target, FieldInfo field, object[] arguments)
        {
            if (arguments.Length == 0)
            {
                return(Task.FromResult(field.GetValue(target)));
            }

            field.SetValue(target, arguments[0]);
            return(Done);
        }
Example #4
0
 static Task <object> DoInvoke(TypedActor target, MemberInfo member, object[] arguments)
 {
     return(member.MemberType == MemberTypes.Field
             ? DoInvoke(target, (FieldInfo)member, arguments)
             : DoInvoke(target, (PropertyInfo)member, arguments));
 }
Example #5
0
 public static Task <object> Invoke(TypedActor target, MemberInfo member, object[] arguments)
 {
     return(member.MemberType == MemberTypes.Method
                ? DoInvoke(target, (MethodInfo)member, arguments)
                : DoInvoke(target, member, arguments));
 }