Skip to content

Instantly share code, notes, and snippets.

@ielcoro
Created March 20, 2012 09:35
Show Gist options
  • Save ielcoro/2133417 to your computer and use it in GitHub Desktop.
Save ielcoro/2133417 to your computer and use it in GitHub Desktop.
Uso de la nueva funcionalidad Method Caller Information para implementar INotifyPropertyChanged
public class EntidadBase: INotifyPropertyChanged
{
protected void Set<T>(ref T campo, T valor, [CallerMemberName] string propiedad= "")
{
if (!Object.Equals(campo, valor))
{
campo= valor;
OnPropertyChanged(propiedad);
}
}
//Implementación de INotifyPropertyChanged
}
public class Persona: EntidadBase
{
private string nombre;
public string Nombre
{
get { return nombre; }
set { Set(ref nombre, value); } // El compilador llena automaticamente el nombre de la propiedad
}
private int edad;
public int Edad
{
get { return edad; }
set { Set(ref edad, value); } // El compilador llena automaticamente el nombre de la propiedad
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment