public class Eventable<T>
{
#region Var
public T Value { get { return _value; } private set { _value = value; RaiseValueChanged(); } }
private T _value;
public delegate void MethodContainer();
public event MethodContainer ValueChanged;
#endregion
#region Init
public Eventable(T Value)
{
this.Value = Value;
}
public static implicit operator Eventable<T>(T Value)
{
return new Eventable<T>(Value);
}
#endregion
#region Actions
protected virtual void RaiseValueChanged()
{
ValueChanged?.Invoke();
}
#endregion
}
public class Intercom
{
#region Обработка событий по изменению содержимых.
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region Управление свойством.
public string Message { get; set; } = "Null";
public bool OnEvent { get; set; } = true;
public void Reset() { Message = "Null"; }
#endregion
#region Внутренее свойство события.
private int _Calling;
private string _Response;
private string _Request;
private string _Report;
public int Calling
{
get { return _Calling; }
set { _Calling = value; if (OnEvent) NotifyPropertyChanged($"Call.{Message}"); }
}
public string Response
{
get { return _Response; }
set { _Response = value; if (OnEvent) NotifyPropertyChanged($"Response.{Message}"); }
}
public string Request
{
get { return _Request; }
set { _Request = value; if (OnEvent) NotifyPropertyChanged($"Request.{Message}"); }
}
public string Report
{
get { return _Report; }
set { _Report = value; if (OnEvent) NotifyPropertyChanged($"Report.{Message}"); }
}
#endregion
}
Eventable<Int32> var = 32;
var.ValueChanged += () => Console.WriteLine(var.Value);
var.Value = 34;
var.Value = 42;