public static()

in src/StructuredLogger/Search/NodeQueryMatcher.cs [322:429]


        public static (string[] array, int count) PopulateSearchFields(BaseNode node)
        {
            var searchFields = searchFieldsThreadStatic;
            int count = 0;

            if (searchFields == null)
            {
                searchFields = new string[MaxArraySize];
                searchFieldsThreadStatic = searchFields;
            }
            else
            {
                Array.Clear(searchFields, 0, MaxArraySize);
            }

            // in case they want to narrow down the search such as "Build target" or "Copy task"
            var typeName = node.TypeName;

            // for tasks derived from Task $task should still work
            if (node is Microsoft.Build.Logging.StructuredLogger.Task t && t.IsDerivedTask)
            {
                searchFields[count++] = "Task";
            }

            searchFields[count++] = typeName;

            if (node is NameValueNode nameValueNode)
            {
                if (!string.IsNullOrEmpty(nameValueNode.Name))
                {
                    searchFields[count++] = nameValueNode.Name;
                }

                if (!string.IsNullOrEmpty(nameValueNode.Value))
                {
                    searchFields[count++] = nameValueNode.Value;
                }
            }
            else if (node is NamedNode named)
            {
                if (!string.IsNullOrEmpty(named.Name))
                {
                    searchFields[count++] = named.Name;
                }

                if (node is TextNode textNode)
                {
                    if (!string.IsNullOrEmpty(textNode.Text))
                    {
                        searchFields[count++] = textNode.Text;
                    }

                    if (node is AbstractDiagnostic diagnostic)
                    {
                        if (!string.IsNullOrEmpty(diagnostic.Code))
                        {
                            searchFields[count++] = diagnostic.Code;
                        }

                        if (!string.IsNullOrEmpty(diagnostic.File))
                        {
                            searchFields[count++] = diagnostic.File;
                        }

                        if (!string.IsNullOrEmpty(diagnostic.ProjectFile))
                        {
                            searchFields[count++] = diagnostic.ProjectFile;
                        }
                    }
                }
                else if (node is TimedNode)
                {
                    if (node is Project project)
                    {
                        if (!string.IsNullOrEmpty(project.TargetFramework))
                        {
                            searchFields[count++] = project.TargetFramework;
                        }

                        if (!string.IsNullOrEmpty(project.TargetsText))
                        {
                            searchFields[count++] = project.TargetsText;
                        }

                        if (!string.IsNullOrEmpty(project.EvaluationText))
                        {
                            searchFields[count++] = project.EvaluationText;
                        }
                    }
                    else if (node is ProjectEvaluation evaluation)
                    {
                        if (!string.IsNullOrEmpty(evaluation.EvaluationText))
                        {
                            searchFields[count++] = evaluation.EvaluationText;
                        }
                    }
                    else if (node is Target target)
                    {
                        if (!string.IsNullOrEmpty(target.ParentTarget))
                        {
                            searchFields[count++] = target.ParentTarget;
                        }
                    }
                }
            }

            return (searchFields, count);
        }