private static void ProcessActivity(ChildActivity childActivity, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining, ActivityCallStack parentChain, ref IList <ValidationError> validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback)
        {
            Activity                element            = childActivity.Activity;
            IList <Constraint>      runtimeConstraints = element.RuntimeConstraints;
            IList <ValidationError> list2 = null;

            if (!element.HasStartedCachingMetadata)
            {
                element.MemberOf.AddMember(element);
                element.InternalCacheMetadata(options.CreateEmptyBindings, ref list2);
                ActivityValidationServices.ValidateArguments(element, element.Parent == null, ref list2);
                ActivityLocationReferenceEnvironment environment  = null;
                ActivityLocationReferenceEnvironment environment2 = new ActivityLocationReferenceEnvironment(element.HostEnvironment)
                {
                    InternalRoot = element
                };
                int nextEnvironmentId = 0;
                ProcessChildren(element, element.Children, ActivityCollectionType.Public, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessChildren(element, element.ImportedChildren, ActivityCollectionType.Imports, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessChildren(element, element.ImplementationChildren, ActivityCollectionType.Implementation, !options.SkipPrivateChildren, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessArguments(element, element.RuntimeArguments, true, ref environment2, ref nextEnvironmentId, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessVariables(element, element.RuntimeVariables, ActivityCollectionType.Public, true, ref environment, ref nextEnvironmentId, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessVariables(element, element.ImplementationVariables, ActivityCollectionType.Implementation, !options.SkipPrivateChildren, ref environment2, ref nextEnvironmentId, ref nextActivity, ref activitiesRemaining, ref list2);
                if (element.HandlerOf != null)
                {
                    for (int i = 0; i < element.HandlerOf.RuntimeDelegateArguments.Count; i++)
                    {
                        RuntimeDelegateArgument argument      = element.HandlerOf.RuntimeDelegateArguments[i];
                        DelegateArgument        boundArgument = argument.BoundArgument;
                        if ((boundArgument != null) && boundArgument.InitializeRelationship(element, ref list2))
                        {
                            boundArgument.Id = nextEnvironmentId;
                            nextEnvironmentId++;
                        }
                    }
                }
                if (environment == null)
                {
                    element.PublicEnvironment = new ActivityLocationReferenceEnvironment(element.GetParentEnvironment());
                }
                else
                {
                    if (environment.Parent == null)
                    {
                        environment.InternalRoot = element;
                    }
                    element.PublicEnvironment = environment;
                }
                element.ImplementationEnvironment = environment2;
                ProcessDelegates(element, element.Delegates, ActivityCollectionType.Public, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessDelegates(element, element.ImportedDelegates, ActivityCollectionType.Imports, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessDelegates(element, element.ImplementationDelegates, ActivityCollectionType.Implementation, !options.SkipPrivateChildren, ref nextActivity, ref activitiesRemaining, ref list2);
                if (callback != null)
                {
                    callback(childActivity, parentChain);
                }
                if (list2 != null)
                {
                    Activity activity2;
                    if (validationErrors == null)
                    {
                        validationErrors = new List <ValidationError>();
                    }
                    string str = ActivityValidationServices.GenerateValidationErrorPrefix(childActivity.Activity, parentChain, out activity2);
                    for (int j = 0; j < list2.Count; j++)
                    {
                        ValidationError item = list2[j];
                        item.Source = activity2;
                        item.Id     = activity2.Id;
                        if (!string.IsNullOrEmpty(str))
                        {
                            item.Message = str + item.Message;
                        }
                        validationErrors.Add(item);
                    }
                    list2 = null;
                }
                if (options.StoreTempViolations && (validationErrors != null))
                {
                    childActivity.Activity.SetTempValidationErrorCollection(validationErrors);
                    validationErrors = null;
                }
            }
            else
            {
                SetupForProcessing(element.Children, true, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.ImportedChildren, false, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.RuntimeArguments, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.RuntimeVariables, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.Delegates, true, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.ImportedDelegates, false, ref nextActivity, ref activitiesRemaining);
                if (!options.SkipPrivateChildren)
                {
                    SetupForProcessing(element.ImplementationChildren, true, ref nextActivity, ref activitiesRemaining);
                    SetupForProcessing(element.ImplementationDelegates, true, ref nextActivity, ref activitiesRemaining);
                    SetupForProcessing(element.ImplementationVariables, ref nextActivity, ref activitiesRemaining);
                }
                if ((callback != null) && !options.OnlyCallCallbackForDeclarations)
                {
                    callback(childActivity, parentChain);
                }
                if (childActivity.Activity.HasTempViolations && !options.StoreTempViolations)
                {
                    childActivity.Activity.TransferTempValidationErrors(ref validationErrors);
                }
            }
            if ((!options.SkipConstraints && parentChain.WillExecute) && (childActivity.CanBeExecuted && (runtimeConstraints.Count > 0)))
            {
                ActivityValidationServices.RunConstraints(childActivity, parentChain, runtimeConstraints, options, false, ref validationErrors);
            }
        }