protected override void ProcessRecord()

in src/PSRule/Commands/AssertExistsCommand.cs [47:91]


        protected override void ProcessRecord()
        {
            if (!IsRuleScope())
                throw RuleScopeException(LanguageKeywords.Exists);

            var targetObject = InputObject ?? GetTargetObject();
            var foundFields = new List<string>();
            var notFoundFields = new List<string>();
            var found = 0;
            var required = All ? Field.Length : 1;

            for (var i = 0; i < Field.Length && found < required; i++)
            {
                if (ObjectHelper.GetPath(
                    bindingContext: PipelineContext.CurrentThread,
                    targetObject: targetObject,
                    path: Field[i],
                    caseSensitive: CaseSensitive,
                    value: out object _))
                {
                    RunspaceContext.CurrentThread.VerboseConditionMessage(
                        condition: RuleLanguageNouns.Exists,
                        message: PSRuleResources.ExistsTrue,
                        args: Field[i]);
                    foundFields.Add(Field[i]);
                    found++;
                }
                else
                    notFoundFields.Add(Field[i]);
            }

            var result = Not ? found < required : found == required;
            RunspaceContext.CurrentThread.VerboseConditionResult(condition: RuleLanguageNouns.Exists, outcome: result);
            if (!(result || TryReason(Reason)))
            {
                WriteReason(Not ? string.Format(
                    Thread.CurrentThread.CurrentCulture,
                    ReasonStrings.ExistsNot,
                    string.Join(", ", foundFields)) : string.Format(
                        Thread.CurrentThread.CurrentCulture,
                        ReasonStrings.Exists,
                        string.Join(", ", notFoundFields)));
            }
            WriteObject(result);
        }