C# - an example of creating an observable object with C# custom event
less than 1 minute read
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| public class ValueChangeData
{
public object oldValue;
public object newValue;
}
public IObservable<ValueChangeData> CreateObservableSourceChange()
{
return Observable.Create<ValueChangeData>(
observer =>
{
DelegateValueChanged changedFunc = new DelegateValueChanged((oldValue, newValue) =>
{
ValueChangeData data = new ValueChangeData();
data.oldValue = oldValue;
data.newValue = newValue;
observer.OnNext(data);
});
OnValueChanged += changedFunc;
return () =>
{
OnValueChanged -= changedFunc;
};
}
);
}
|