to be tested
This commit is contained in:
parent
26f0079087
commit
8403a9aaca
1 changed files with 59 additions and 0 deletions
59
BookAStar/BookAStar/Helpers/ObservableString.cs
Normal file
59
BookAStar/BookAStar/Helpers/ObservableString.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace BookAStar
|
||||||
|
{
|
||||||
|
public class ObservableString : IObservable<string>, IDisposable
|
||||||
|
{
|
||||||
|
public ObservableString(string data)
|
||||||
|
{
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
private string data = null;
|
||||||
|
private List<IObserver<string>> observers = new List<IObserver<string>>();
|
||||||
|
|
||||||
|
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<string> observer)
|
||||||
|
{
|
||||||
|
observers.Add(observer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue