Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a person class which has the following properties:
Id, Name,LoggedInStatus which I get from Visual Studio Intellisense.
You can image the class to be something like as shown below.
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public bool LoggedInStatus{ get; set; }
}
However, I cannot modify the Person class as it is obtained from as a dll from another project (via added reference to .csproj) and also I am not permitted to do so thus preventing me from implementing the INotifyProperyChanged approach.
I need to monitor the property LoggedInStatus for any change and take a necessary action.
Please help.

What I have tried:

Out of ideas. I don't know how to proceed.
Posted
Updated 16-Aug-18 5:47am

1 solution

Public class MyPerson : Person, INotifyPropertyChanged

etc.

Setters don't need changing; you can call OnPropertyChanged on an instance (with or without a property name) from anywhere.
 
Share this answer
 
Comments
Member 13046192 16-Aug-18 12:15pm    
Hi. Thank you. But I still can't seem to get this. Please help. The code is as follows:
public class MyPerson : Person,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;


[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

class Program
{
static void Main(string[] args)
{

MyPerson x= new MyPerson();
x.PropertyChanged += X_PropertyChanged;
x.LoggedInStatus = true;
x.LoggedInStatus = false;
x.LoggedInStatus = true;
}

private static void X_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{

}
}
Member 13046192 16-Aug-18 12:16pm    
It must hit X_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) method everytime the LoggedInStatus changes from true to false and viceversa. But it isn't.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900