造型,属性已更改并设置了相同的值? [英] Fody, propertychanged and setting same value?

查看:128
本文介绍了造型,属性已更改并设置了相同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以配置fody来不检查设置为property的值-我遇到的情况是value相同并且我想要设置属性,因为我在属性设置器中有其他逻辑未调用./p>

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.

推荐答案

这显然比最初的问题晚了几年,但可供将来参考:

确实可以通过修改FodyWeavers.xml文件中的选项来实现.

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

如PropertyChanged.Fody wiki 所示,其中一个选项称为CheckForEquality,可以设置为false(默认为true).这将防止Fody注入相等性检查代码. FodyWeavers.xml文件现在可能如下所示:

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>

如评论中所述,还可以通过DoNotCheckEquality属性针对每个属性执行此操作,例如

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; }
}

请参见 wiki/Attributes

这篇关于造型,属性已更改并设置了相同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆