Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/SettingContainer.cpp (C++)

Code before:

        if (const auto& content{ Content() })
        {
            if (const auto& obj{ content.try_as<DependencyObject>() })
            {
                // apply header text as name (automation property)
                if (const auto& header{ Header() })
                {
                    const auto headerText{ header.try_as<hstring>() };
                    if (headerText && !headerText->empty())
                    {
                        Automation::AutomationProperties::SetName(obj, *headerText);
                    }
                }

                // apply help text as tooltip and full description (automation property)
                const auto& helpText{ HelpText() };
                if (!helpText.empty())
                {
                    Controls::ToolTipService::SetToolTip(obj, box_value(helpText));
                    Automation::AutomationProperties::SetFullDescription(obj, helpText);
                }
            }
        }

        if (const auto& child{ GetTemplateChild(L"Expander") })
        {
            if (const auto& expander{ child.try_as<Microsoft::UI::Xaml::Controls::Expander>() })
            {
                // apply header text as name (automation property)
                if (const auto& header{ Header() })
                {
                    const auto headerText{ header.try_as<hstring>() };
                    if (headerText && !headerText->empty())
                    {
                        Automation::AutomationProperties::SetName(expander, *headerText);
                    }
                }

                // apply help text as tooltip and full description (automation property)
                const auto& helpText{ HelpText() };
                if (!helpText.empty())
                {
                    Controls::ToolTipService::SetToolTip(expander, box_value(helpText));
                    Automation::AutomationProperties::SetFullDescription(expander, helpText);
                }
            }
        }

        if (HelpText().empty())
        {

Review comment (suggestion):
We should probably reorder these to be...
```c++
if (/*we have an Expander*/) {/*apply Auto Props to expander control*/}
else if (/*we have Content*/) { /*apply Auto Props to content*/ }
```
That way we aren't redundantly applying the Auto Props.

Code after:

        // Get the correct base to apply automation properties to
        DependencyObject base{ nullptr };
        if (const auto& child{ GetTemplateChild(L"Expander") })
        {
            if (const auto& expander{ child.try_as<Microsoft::UI::Xaml::Controls::Expander>() })
            {
                base = child;
            }
        }
        else if (const auto& content{ Content() })
        {
            if (const auto& obj{ content.try_as<DependencyObject>() })
            {
                base = obj;
            }
        }

        if (base)
        {
            // apply header as name (automation property)
            if (const auto& header{ Header() })
            {
                if (const auto headerText{ header.try_as<hstring>() })
                {
                    Automation::AutomationProperties::SetName(base, *headerText);
                }
            }

            // apply help text as tooltip and full description (automation property)
            if (const auto& helpText{ HelpText() }; !helpText.empty())
            {
                Controls::ToolTipService::SetToolTip(base, box_value(helpText));
                Automation::AutomationProperties::SetFullDescription(base, helpText);
            }
        }

        if (HelpText().empty())
        {
            if (const auto& child{ GetTemplateChild(L"HelpTextBlock") })
            {
                if (const auto& textBlock{ child.try_as<Controls::TextBlock>() })
                {
                    textBlock.Visibility(Visibility::Collapsed);
                }
            }
        }
    }

    // Method Description:
    // - Updates the override system visibility and text