wpf 使用 Fody 时出错 [ImplementPropertyChanged]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44470333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 14:06:02  来源:igfitidea点击:

Error on using Fody [ImplementPropertyChanged]

c#wpfmvvmfody

提问by A.Hussainy

I am Using VS 2017 Community Edition I am creating MVVM pattern. After i installed fody i got error on my code while the instructor of the tutorial implemented it on vs 2015 here is the code:

我正在使用 VS 2017 Community Edition 我正在创建 MVVM 模式。安装 fody 后,我的代码出现错误,而本教程的讲师在 vs 2015 上实现了它,代码如下:

using PropertyChanged;
using System.ComponentModel;

namespace GProject_MVVM.ViewModel
{
    /// <summary>
    /// A base view model that fires Property Changed events as needed
    /// </summary>
    [ImplementPropertyChanged] // **I got error here**
    public class BaseViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// The event that is fired when any child property changes its value
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
        /// <summary>
        /// Call this to fire <see cref="PropertyChanged"/> event
        /// </summary>
        /// <param name="name"></param>
        public void OnPropertyChanged(string name)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));

        }
    }
}

[ImplementPropertyChanged] should not make error on this point the instructor implemented it successfully so is thier anything missing on my code ? The error says:

[ImplementPropertyChanged] 在这一点上不应出错,讲师已成功实施它,所以我的代码中是否缺少任何内容?错误说:

Severity Code Description Project File Line Suppression State Error CS0619 'ImplementPropertyChangedAttribute' is obsolete: 'This configuration option has been deprecated. The use of this attribute was to add INotifyPropertyChanged to a class with its associated event definition. After that all classes that implement INotifyPropertyChanged have their properties weaved, weather they have the ImplementPropertyChangedAttribute or not. This attribute was often incorrectly interpreted as an opt in approach to having properties weaved, which was never the intent nor how it ever operated. This attribute has been replaced by AddINotifyPropertyChangedInterfaceAttribute.' GProject_MVVM c:\users\ahmed hussainy\documents\visual studio 2017\Projects\GProject_MVVM\GProject_MVVM\ViewModel\BaseViewModel.cs 9 Active

严重性代码描述项目文件行抑制状态错误 CS0619 'ImplementPropertyChangedAttribute' 已过时:'此配置选项已被弃用。此属性的用途是将 INotifyPropertyChanged 添加到具有关联事件定义的类。之后,实现 INotifyPropertyChanged 的​​所有类都编织了它们的属性,无论它们是否具有ImplementPropertyChangedAttribute。这个属性经常被错误地解释为一种选择编织属性的方法,这从来不是它的意图,也不是它的操作方式。此属性已被 AddINotifyPropertyChangedInterfaceAttribute 取代。GProject_MVVM c:\users\ahmed hussainy\documents\visual studio 2017\Projects\GProject_MVVM\GProject_MVVM\ViewModel\BaseViewModel。

回答by woelliJ

The exception already states the answer.

异常已经给出了答案。

ImplementPropertyChangedAttribute' is obsolete: 'This configuration option has been deprecated. The use of this attribute was to add INotifyPropertyChanged to a class with its associated event definition. After that all classes that implement INotifyPropertyChanged have their properties weaved, weather they have the ImplementPropertyChangedAttribute or not.

ImplementPropertyChangedAttribute' 已过时:'此配置选项已被弃用。此属性的用途是将 INotifyPropertyChanged 添加到具有关联事件定义的类。之后,实现 INotifyPropertyChanged 的​​所有类都编织了它们的属性,无论它们是否具有ImplementPropertyChangedAttribute。

With the new version of Fody.PropertyChanged you don't need to add the attribute any longer. Just make that class you want to be weaved implement INotifyPropertyChangedand it will work.

使用新版本的 Fody.PropertyChanged,您不再需要添加该属性。只需让你想要编织的那个类实现INotifyPropertyChanged,它就会起作用。

So basically just remove / delete [ImplementPropertyChanged]and it will compile and weave (if the weaver is present in FodyWeavers.xml)

所以基本上只需删除/删除[ImplementPropertyChanged]它就会编译和编织(如果编织器存在于FodyWeavers.xml