让我的业务对象实现 INotifyPropertyChanged

Making my business objects implement INotifyPropertyChanged

我正在尝试使用 MVVMLight 中的 Set() 方法使我的业务对象实现 INotifyPropertyChanged。这是我目前所拥有的:

public class Person : ObservableObject
{
    private readonly Entities.Person entity;

    public Person()
    {
        entity = new Entities.Person();
    }

    public int ID
    {
        get { return entity.Id; }
        set { Set(() => ID, ref entity.Id, value); }
    }
}

显然,我无法执行此操作,因为出现以下错误: A property or indexer may not be passed as an out or ref parameter

我应该怎么做?我需要直接实施 INotifyPropertyChanged 还是有其他方法可以做到这一点?

问题是:entity.Id 是一个 属性。 您可以使用变通方法:

set 
{ 
int id;
Set(() => ID, ref id , value); 
entity.Id=id;
}

尝试更改:

Set(() => ID, ref id , value);

收件人:

var obj = entity.Id;
Set(() => ID, ref obj, value); 
entity.Id=obj;