-
-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PropertyChanging.Fody weaver interfering with PropertyChanged.Fody equality check option #1100
Comments
@SimonCropp let me know if you want me to add a PR for a test for this |
Since weavers don't know about each other, there is nothing |
I don't know enough about the internals, but my hunch is that it should be possible to adjust the weaver in a way that this is not the case, with possibly a slight hit to performance. Right now the check for equality IL code is something like:
and it could be:
which would allow a composable:
It boils down to whether weavers are supposed to be maximally compatible or maximally performant. Defensive programming has a cost. Might possibly make sense to have a config option for this, which you would set if you want to apply multiple weavers? I assume this would happen for PropChanging/PropChanged.Fody with CheckEquality true alongside any weaver that adds anything to the property. If the weaver's intention is to "add a PropertyChang(ing/ed).Fody" automatically, but without intending to "prevent any other calls in the property to happen", then it would make sense to call this a bug or undocumented behavior. It's not only weavers that are interferred with. If you use the following, the non-weaved CustomCallback will also be skipped because of the early return:
Worst case scenario that still resolves the bug is to document the incompatibility. Then it's simply a limitation by design. |
I never found a real use case for
|
I agree about relative limited utility of PropertyChanging compared to this repo. Inserting equality check option in both wouldn't fix it though, they'd still conflict when one is set to false other to true. More importantly, this has uncovered a broader issue which this one can probably be seen simply as a subset of: I.e. this isn't only a multi-weaver issue, it's PropertyChanged.Fody and PropertyChanging.Fody's weavers doing undocumented changes to the setters, applying their equality checks at a too broad scope, interfering with expected behavior (insert PropertyChanged, don't break anything else). |
Added pull request with tests demonstrating this: |
The same issue exists in PropertyChanging.Fody, I'll add a separate issue there. |
This behavior is now property documented: https://github.com/Fody/PropertyChanged/wiki/EqualityChecking |
Describe the issue
PropertyChanging.Fody interferes with PropertyChanged.Fody option "CheckForEquality".
Assuming that the two modules are intended to be compatible:
#169
Basic behavior seems to be correct. But PropertyChanged.Fody's CheckForEquality = false will be ignored for classes also implementing INotifyPropertyChanging, I assume due to weavers conflicting in some way.
For a class like:
The relevant part of IL code with PropertyChanged.Fody alone will look like:
With added INotifyPropertyChanging and PropertyChanging.Fody:
Diff of IL codes:
The first class will fire an event on assignment of same value; the second class will ignore it despite the DoNotCheckEquality attribute.
The same happens if the option is configured via weavers.xml
The same happens if the interface is explicitly implemented without the AddINotifyPropertyChangedInterface attribute.
Minimal Repro
Used the following test on a set of test classes:
The class & test projects (VS2022 Community 17.12, NET9.0, Fody 6.9.1, PropertyChanged.Fody 4.1.0, PropertyChanging.Fody 1.30.3) :
FodyTest.zip
I can add a PR with the tests if desired, just wasn't sure which repo it should go to - here makes more sense I think.
The text was updated successfully, but these errors were encountered: