diff --git a/BookAStar/BookAStar/Helpers/ObservableString.cs b/BookAStar/BookAStar/Helpers/ObservableString.cs new file mode 100644 index 00000000..2049d950 --- /dev/null +++ b/BookAStar/BookAStar/Helpers/ObservableString.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; + +namespace BookAStar +{ + public class ObservableString : IObservable, IDisposable + { + public ObservableString(string data) + { + this.data = data; + } + private string data = null; + private List> observers = new List>(); + + public string Data + { + get + { + return data; + } + + set + { + if (data != value) + { + data = value; + foreach (var obs in observers) + obs.OnCompleted(); + } + } + } + + public override string ToString() + { + return data; + } + + public static explicit operator ObservableString (string data) + { + return new ObservableString(data); + } + + public static explicit operator string (ObservableString observable) + { + return observable.ToString(); + } + + public void Dispose() + { + observers = null; + } + + public IDisposable Subscribe(IObserver observer) + { + observers.Add(observer); + return this; + } + } +} \ No newline at end of file