User avatar
sfernandez
Site Admin
Posts: 3014
Joined: 22 Dec 2011, 19:20

Re: Problem with custom "SwitchConverter" and Static Resources

25 Oct 2021, 12:50

Hi, looking at the code you sent me I see the collection is not initialized:
SwitchConverter::SwitchConverter(): m_switchCases(Noesis::MakePtr<SwitchCaseCollection>()) {
    ConnectNode(m_switchCases, this);
    InitComponent(m_switchCases, true);
}
And I think the implementation of the converter has a bug because you are comparing When and Then properties, shouldn't you be comparing When against the bound value?
bool SwitchConverter::TryConvert(Noesis::BaseComponent* value, const Noesis::Type*,
    Noesis::BaseComponent*, Noesis::Ptr<Noesis::BaseComponent>& result) {
    int numCases = m_switchCases->Count();
    for (int i = 0; i < numCases; ++i) {
        auto switchCase = m_switchCases->Get(i);
        if (switchCase) {
            auto when = switchCase->GetWhen();
            if (when) {
                if (when->Equals(value)) {
                    auto then = switchCase->GetThen();
                    result.Reset(then);
                }
            }
            else {
                NS_LOG_WARNING("SwitchConverter: SwitchCase WHEN is null");
            }
        }
    }
    return true;
}

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests