Page 2 of 2

Re: Problem with custom "SwitchConverter" and Static Resources

Posted: 25 Oct 2021, 12:50
by sfernandez
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;
}