使我的业务对象实现INotifyPropertyChanged

本文关键字:实现 INotifyPropertyChanged 对象 业务 我的 | 更新日期: 2023-09-27 18:18:09

我试图使我的业务对象使用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直接还是有另一种方式来做到这一点?

使我的业务对象实现INotifyPropertyChanged

尝试改变:

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

:

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

问题是:entity.Id是一个属性。你可以使用work around:

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