コード例 #1
0
        public static ClrInstance[] TryResolveContinuations(ClrInstance continuation, CausalityContext context)
        {
            if (continuation.IsListOfObjects())
            {
                var result = new List <ClrInstance>();
                int size   = (int)continuation["_size"].Instance.ValueOrDefault !;
                var items  = continuation["_items"].Instance.Items;

                for (int i = 0; i < size; i++)
                {
                    var continuationItem = TryResolveContinuationInstance(items[i], context);
                    if (continuationItem != null)
                    {
                        result.Add(continuationItem);
                    }

                    return(result.ToArray());
                }
            }

            var resolvedContinuation = TryResolveContinuationInstance(continuation, context);

            if (resolvedContinuation != null)
            {
                return(new[] { resolvedContinuation });
            }

            return(Array.Empty <ClrInstance>());
        }
コード例 #2
0
        public static ClrInstance?TryResolveContinuationInstance(ClrInstance continuation, CausalityContext context)
        {
            if (continuation.IsOfType(context.Registry.StandardTaskContinuationType))
            {
                return(continuation["m_task"].Instance);
            }

            if (continuation.IsTaskCompletionSource(context))
            {
                return(continuation["m_task"].Instance);
            }

            if (continuation.IsCompletedTaskContinuation(context))
            {
                // Continuation is a special sentinel instance that indicates that the task is completed.
                return(null);
            }

            if (continuation.IsOfType(typeof(Action), context))
            {
                return(TryResolveContinuationForAction(continuation, context));
            }

            if (continuation.IsOfType(context.Registry.AwaitTaskContinuationIndex) || continuation.IsOfType(context.Registry.TaskIndex))
            {
                return(TryResolveContinuationForAction(continuation["m_action"].Instance, context));
            }

            // Need to compare by name since GetTypeByName does not work for the generic type during initialization
            if (continuation.IsListOfObjects())
            {
                Contract.Assert(false, "Please call 'TryResolveContinuations' for a list of continuations.");
            }

            return(null);
        }