Advertisement
Fhernd

UsoINotifyPropertyChanged.cs

Jul 15th, 2015
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. // OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. using System;
  4. using System.ComponentModel;
  5. using System.Runtime.CompilerServices;
  6.  
  7. public class UsoINotifyPropertyChanged : INotifyPropertyChanged
  8. {
  9.     public event PropertyChangedEventHandler PropertyChanged = delegate{};
  10.    
  11.     public void InvocarAlCambioPropiedad([CallerMemberName] string nombrePropiedad = null)
  12.     {
  13.         PropertyChanged(this, new PropertyChangedEventArgs(nombrePropiedad));
  14.         Console.WriteLine(nombrePropiedad);
  15.     }
  16.    
  17.     string nombreCliente;
  18.    
  19.     public String NombreCliente
  20.     {
  21.         get
  22.         {
  23.             return nombreCliente;
  24.         }
  25.         set
  26.         {
  27.             if (value == nombreCliente) return;
  28.            
  29.             nombreCliente = value;
  30.             InvocarAlCambioPropiedad(); // El compilador convierte esta
  31.                                         // llamada en InvocarAlCambioPropiedad("NombreCliente");
  32.         }
  33.     }
  34.    
  35.     int idClient;
  36.    
  37.     public int IDCliente
  38.     {
  39.         get
  40.         {
  41.             return idClient;
  42.         }
  43.         set
  44.         {
  45.             if (value == idClient) return;
  46.            
  47.             idClient = value;
  48.             InvocarAlCambioPropiedad(); // El compilador convierte esta
  49.                                         // llamada en InvocarAlCambioPropiedad("IDCliente");
  50.         }
  51.     }
  52. }
  53.  
  54. public class Prueba
  55. {
  56.     public static void Main()
  57.     {
  58.         Console.WriteLine(Environment.NewLine);
  59.        
  60.         UsoINotifyPropertyChanged var = new UsoINotifyPropertyChanged();
  61.        
  62.         var.NombreCliente = "Julio";
  63.         var.IDCliente = 951753852;
  64.        
  65.         Console.WriteLine(Environment.NewLine);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement