Esempio n. 1
0
        private static void Send(ConcurrentObject @object, string name, bool wait, object[] args)
        {
            var method = @object
                         .GetType()
                         .GetMethods()
                         .Where(m => m.Name == name &&
                                m
                                .ReturnType
                                .ToString()
                                .Contains("Task"))
                         .SingleOrDefault();

            if (method != null)
            {
                args = args.Union(new object[] { true }).ToArray();
                var tsk = method.Invoke(@object, args);

                if (wait)
                {
                    ((Task)tsk).Wait();
                }
            }
            else
            {
                var property = @object
                               .GetType()
                               .GetProperty(name);

                Debug.Assert(property != null && property.CanWrite);
                property.SetValue(@object, args[0]);
            }
        }
Esempio n. 2
0
        private static void RunStep(ConcurrentObject @object, string methodName, Func <string> moveNext, Action <Exception> failure)
        {
            var method = @object.GetType().GetMethod(methodName, new[]
            {
                typeof(Action <object>),
                typeof(Action <Exception>),
            });

            Action <object> success = (res) =>
            {
                try
                {
                    var next = moveNext();
                    if (next != null)
                    {
                        RunStep(@object, next, moveNext, failure);
                    }
                }
                catch (Exception ex)
                {
                    failure(ex);
                }
            };

            method.Invoke(@object, new object[] { success, failure });
        }