Context invokes callbacks even if value of context data hasn't changed

Create issue
Issue #47 resolved
Christian Oeing repo owner created an issue

Reported via Mail:

Unfortunately we've registered some strange behaviour in view of using the RegisterListener within the Context class (to automatically react due to some input field changes).

In view of this, I'will get into the callback method twice (not as excpected once).

So I think the only thing, which has to be adapted is the check within the Context.cs file (row 238) from if (value == this.value)

to ​ if (((value != null) && value.GetType().IsValueType) ? value.Equals(this.value) : value == this.value)

So could you please change/adapt this in your library?

It might be possible that doing an == check isn't enough for checking that a string hasn't changed and we need an Equals(value, this.value) check there.

Comments (4)

  1. Christian Oeing reporter

    The problem occurs because of the boxing to System.Object of the values (see https://stackoverflow.com/questions/1659097/why-would-you-use-string-equals-over)

    The suggested solution

    if (((value != null) && value.GetType().IsValueType) ? value.Equals(this.value) : value == this.value)
    

    won't work as System.String is a reference type and not a value type.

    Instead the comparison will use the Equals instead of ==

    if (this.value != null && this.value.Equals(value))
    

    This may have a little overhead if custom reference types have (slow) custom Equals methods, but that's justifiable.

  2. Log in to comment