79538879

Date: 2025-03-27 12:43:04
Score: 1
Natty:
Report link

Can you bake your own class for this? I've written a little sudo code for a demo, if you need a more concrete example I can provide one at a later time.

InMemoryOptionsMonitor {
    
    T _value;

    ctor(T value) {
        _value = value;
    }   

    event EventHandler<T> OnChange;

    void Replace(T newValue)
    {
        _value = newValue;
        OnChange.Invoke(this, newValue);
    }
    ## OR
    void Update(Action<T> update)
    {
        update(_value);
        OnChange.Invoke(this, _value);
    }

    T Current() => _value;
}

I would preferable use T to be a readonly struct/record, then consumers can only update the value in the Options monitor through the replace method

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Can you
  • Low reputation (1):
Posted by: Daniel Brandenburg