using System.ComponentModel; namespace TinyChat; /// /// Represents text-based message content. /// public class ChangingMessageContent : IChatMessageContent { private readonly INotifyPropertyChanged? _value; /// /// Occures when the value of the message content gets changed. /// public event PropertyChangedEventHandler? PropertyChanged; /// /// Initializes a new instance of the class. /// /// The string value of the message content. public ChangingMessageContent(INotifyPropertyChanged? value) { if (value == _value) return; if (_value is not null) _value.PropertyChanged -= NotifyChangedValue; _value = value; NotifyChangedValue(null, null); if (value is not null) value.PropertyChanged += NotifyChangedValue; } /// public object? Content => _value; /// public override string ToString() => _value?.ToString() ?? string.Empty; private void NotifyChangedValue(object? _, PropertyChangedEventArgs? __) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Content))); } }