Estimated value in the setter is not even verified

I have a property in a composite control that checks to see if the value has changed before actually setting the associated private field and performing several other actions.

However, it seems that he never appreciates the statement.

Here is the code for the property:

public T SearchCriteria
        {
            get
            {
                return mySearchCriteria;
            }
            set
            {
                if (value != mySearchCriteria)
                {
                    mySearchCriteria = value;
                    EnsureChildControls();
                    SearchGridParser parser = SearchGridParserFactory.GetParser(this.Type);
                    parser.SetSearchPanelControls<T>(this.mySearchCriteria, ref mySearchParametersPanel);
                    GridView.PageIndex = 0;
                }
            }
        }

I went through the code, and every time it gets the value "value! = MySearchCriteria", it evaluates to false and skips the code inside the if statement. In fact, he does this even when I change it to "value == mySearchCriteria" .. if he just completely skips it no matter how it is evaluated!

What the hey

I tried changing the order of the arguments in validation, and also using object.Equals (), but none of these changes made any difference.

Equals,! =, == GetHashCode.

, "==" "! =" , , .

, . "==", "! =", "Equals" "GetHashCode", , "value!= MySearchCriteria".

.

+3
1

== . , , ==, . ( , , "" == != , - . , , .)

:

, "==" "! =" , , .

, ... , , , , . , , ==, .

, where T : class, , , , , T.

EqualityComparer.Default<T>.Equals(value, mySearchCriteria) Equals, IEquatable<T>.

+4

Source: https://habr.com/ru/post/1773639/


All Articles