Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalWindow.cpp (C++)

Code before:
        }
    }

    winrt::hstring WindowProperties::WindowName() const noexcept
    {
        return _WindowName;
    }

    void WindowProperties::WindowName(const winrt::hstring& value)
    {
        if (_WindowName != value)
        {
            _WindowName = value;
            _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"WindowName" });
            _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" });
        }
    }
    uint64_t WindowProperties::WindowId() const noexcept
    {
        return _WindowId;
    }

    void WindowProperties::WindowId(const uint64_t& value)
    {
        _WindowId = value;
    }

    // Method Description:
    // - Returns a label like "Window: 1234" for the ID of this window
    // Arguments:
    // - <none>
    // Return Value:
    // - a string for displaying the name of the window.
    winrt::hstring WindowProperties::WindowIdForDisplay() const noexcept
    {
        return winrt::hstring{ fmt::format(L"{}: {}",
                                           std::wstring_view(RS_(L"WindowIdLabel")),
                                           _WindowId) };
    }

    // Method Description:
    // - Returns a label like "<unnamed window>" when the window has no name, or the name of the window.
    // Arguments:
    // - <none>
    // Return Value:
    // - a string for displaying the name of the window.
    winrt::hstring WindowProperties::WindowNameForDisplay() const noexcept
    {
        return _WindowName.empty() ?
                   winrt::hstring{ fmt::format(L"<{}>", RS_(L"UnnamedWindowName")) } :
                   _WindowName;

Review comment (suggestion):
You could alternatively just check if `_root` exists. That way we avoid constructing them in the first place.

Code after:
        if (_root)
        {
            _root->HandoffToElevated(_settings);
            return;
        }
    }

    winrt::hstring WindowProperties::WindowName() const noexcept
    {
        return _WindowName;
    }

    void WindowProperties::WindowName(const winrt::hstring& value)
    {
        if (_WindowName != value)
        {
            _WindowName = value;
            // If we get initialized with a window name, this will be called
            // before XAML is stood up, and constructing a
            // PropertyChangedEventArgs will throw.
            try
            {
                _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"WindowName" });
                _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" });
            }
            CATCH_LOG();
        }
    }
    uint64_t WindowProperties::WindowId() const noexcept
    {
        return _WindowId;
    }

    void WindowProperties::WindowId(const uint64_t& value)
    {
        _WindowId = value;
    }

    // Method Description:
    // - Returns a label like "Window: 1234" for the ID of this window
    // Arguments:
    // - <none>
    // Return Value:
    // - a string for displaying the name of the window.
    winrt::hstring WindowProperties::WindowIdForDisplay() const noexcept
    {
        return winrt::hstring{ fmt::format(L"{}: {}",
                                           std::wstring_view(RS_(L"WindowIdLabel")),
                                           _WindowId) };
    }