Skip to content

Unintended side effects of weaver on setters with custom logic #1101

@xeniorn

Description

@xeniorn

Describe the issue

PropertyChanged.Fody weaver makes unintended changes to behavior of setters with custom logic. Specifically, it prevents any custom code in the setter from firing when the value is unchanged, except when configured not to check for equality.

Minimal Repro

Test cases demonstrating this added here
Pull request will be created.

Make an effort to fix the bug

To fix this behavior, the weaver would have to be adjusted so that the control logic using the equality check is constrained only to the OnPropertyChanged injection, rather than indiscriminately applying to the setter as a whole.

So EnqualityCheckWeaver.cs:InjectEqualityCheck(Instruction targetInstruction, TypeReference targetType, TypeReference declaringType) would have to be adjusted.

  1. to ensure custom code prior to backing field/property assignment is run, it should accept an insertion site as input, or detect the proper insertion site internally

  2. to ensure custom code after backing field/property assignment is run, the inserted instructions should not be equivalent to if (true) return; else //continue i.e. using OpCodes.Ret, but rather if (true) //continue; else OnPropChanged();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions