-1

I'm trying to make my business objects implement INotifyPropertyChanged using the Set() method in MVVMLight. This is what I have so far:

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

Obviously, I can't do this because I get the error: A property or indexer may not be passed as an out or ref parameter

How should I do this? Do I need to implement INotifyPropertyChanged directly or is there another way to do this?

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
Jake
  • 1,701
  • 3
  • 23
  • 44
  • Did the accepted answer really help? Seems unlikely. – H H Oct 16 '15 at 12:25
  • Well it's got rid of the error and my code compiles. I'd say that helps. – Jake Oct 16 '15 at 12:27
  • 1
    It's not the same code and it does not look like a replacement for what you've got. – H H Oct 16 '15 at 15:14
  • As @HenkHolterman says, you should only mark it as accepted once you have tested and verifies it works. If only something compiling was a sign it actually worked. – Daniel Kelley Oct 16 '15 at 15:36
  • @DanielKelley, it's compiling, my application is working as expected. So what else do I need to test/verify...? – Jake Oct 16 '15 at 15:59

2 Answers2

1

Try change:

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

To:

var obj = entity.Id;
Set(() => ID, ref obj, value); 
entity.Id=obj;
Mariusz
  • 442
  • 5
  • 16
0

The problem is : entity.Id is a property. you can use work around:

set 
{ 
int id;
Set(() => ID, ref id , value); 
entity.Id=id;
}
Nikita Shrivastava
  • 2,978
  • 10
  • 20