Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/FolderEntry.cpp (C++)

Code before:
FolderEntry::FolderEntry(const winrt::hstring& name) noexcept :
    FolderEntryT<FolderEntry, NewTabMenuEntry>(NewTabMenuEntryType::Folder),
    _Name{ name }
{
}

Json::Value FolderEntry::ToJson() const
{
    auto json = NewTabMenuEntry::ToJson();

    JsonUtils::SetValueForKey(json, NameKey, _Name);
    JsonUtils::SetValueForKey(json, IconKey, _Icon);
    JsonUtils::SetValueForKey(json, EntriesKey, _Entries);
    JsonUtils::SetValueForKey(json, InliningKey, _Inlining);
    JsonUtils::SetValueForKey(json, AllowEmptyKey, _AllowEmpty);

    return json;
}

winrt::com_ptr<NewTabMenuEntry> FolderEntry::FromJson(const Json::Value& json)
{
    auto entry = winrt::make_self<FolderEntry>();

    JsonUtils::GetValueForKey(json, NameKey, entry->_Name);
    JsonUtils::GetValueForKey(json, IconKey, entry->_Icon);
    if (const auto& entries{ JsonUtils::GetValueForKey<decltype(entry->_Entries)>(json, EntriesKey) })
    {
        entry->_Entries = entries;
    }
    JsonUtils::GetValueForKey(json, InliningKey, entry->_Inlining);
    JsonUtils::GetValueForKey(json, AllowEmptyKey, entry->_AllowEmpty);

    return entry;
}

// A FolderEntry should only expose the entries to actually render to WinRT,
// to keep the logic for collapsing/expanding more centralised.
using NewTabMenuEntryModel = winrt::Microsoft::Terminal::Settings::Model::NewTabMenuEntry;
IVector<NewTabMenuEntryModel> FolderEntry::Entries() const
{
    // We filter the full list of entries from JSON to just include the
    // non-empty ones.
    IVector<NewTabMenuEntryModel> result{ winrt::single_threaded_vector<NewTabMenuEntryModel>() };
    if (_Entries == nullptr)
    {
        return result;
    }

    for (const auto& entry : _Entries)
    {
        if (entry == nullptr)

Review comment (suggestion):
Can you explain quick how this is different from `GetValueForKey(..., into)`? It seems largely the same, but more verbose and error-prone.

Code after:
FolderEntry::FolderEntry(const winrt::hstring& name) noexcept :
    FolderEntryT<FolderEntry, NewTabMenuEntry>(NewTabMenuEntryType::Folder),
    _Name{ name }
{
}

Json::Value FolderEntry::ToJson() const
{
    auto json = NewTabMenuEntry::ToJson();

    JsonUtils::SetValueForKey(json, NameKey, _Name);
    JsonUtils::SetValueForKey(json, IconKey, _Icon);
    JsonUtils::SetValueForKey(json, EntriesKey, _Entries);
    JsonUtils::SetValueForKey(json, InliningKey, _Inlining);
    JsonUtils::SetValueForKey(json, AllowEmptyKey, _AllowEmpty);

    return json;
}

winrt::com_ptr<NewTabMenuEntry> FolderEntry::FromJson(const Json::Value& json)
{
    auto entry = winrt::make_self<FolderEntry>();

    JsonUtils::GetValueForKey(json, NameKey, entry->_Name);
    JsonUtils::GetValueForKey(json, IconKey, entry->_Icon);
    JsonUtils::GetValueForKey(json, EntriesKey, entry->_Entries);
    JsonUtils::GetValueForKey(json, InliningKey, entry->_Inlining);
    JsonUtils::GetValueForKey(json, AllowEmptyKey, entry->_AllowEmpty);

    return entry;
}

// A FolderEntry should only expose the entries to actually render to WinRT,
// to keep the logic for collapsing/expanding more centralised.
using NewTabMenuEntryModel = winrt::Microsoft::Terminal::Settings::Model::NewTabMenuEntry;
IVector<NewTabMenuEntryModel> FolderEntry::Entries() const
{
    // We filter the full list of entries from JSON to just include the
    // non-empty ones.
    IVector<NewTabMenuEntryModel> result{ winrt::single_threaded_vector<NewTabMenuEntryModel>() };
    if (_Entries == nullptr)
    {
        return result;
    }

    for (const auto& entry : _Entries)
    {
        if (entry == nullptr)
        {
            continue;
        }