Fody, propertychanged and setting same value?

陌路散爱 提交于 2021-02-07 21:51:46

问题


Is there any way to configure fody to not check the value which is set to property - I have situations when value is the same and I want property to be set because I have additional logic in property setter that is not invoked.


回答1:


This is clearly literally years after the original question but for future reference:

This is indeed possible by modifying the options in the FodyWeavers.xml file.

As is shown on the PropertyChanged.Fody wiki, one of the options is called CheckForEquality and can be set to false (it defaults to true). This will prevent Fody from injecting equality checking code. The FodyWeavers.xml file could now look as follows:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <PropertyChanged CheckForEquality='false'/>
</Weavers>

As noted in the comments there is also the possibility to do this per property via the DoNotCheckEquality attribute e.g.

[ImplementPropertyChanged]
public class Person 
{
    [DoNotCheckEquality]
    public string Name { get; set; }
}

See wiki/Attributes



来源:https://stackoverflow.com/questions/24202653/fody-propertychanged-and-setting-same-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!