csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
#nullable enable
|
|
using System;
|
|
using Avalonia.Data;
|
|
|
|
namespace Avalonia.Benchmarks
|
|
{
|
|
internal class TestBindingObservable<T> : IObservable<BindingValue<T?>>, IDisposable
|
|
{
|
|
private T? _value;
|
|
private IObserver<BindingValue<T?>>? _observer;
|
|
|
|
public TestBindingObservable(T? initialValue = default) => _value = initialValue;
|
|
|
|
public IDisposable Subscribe(IObserver<BindingValue<T?>> observer)
|
|
{
|
|
if (_observer is object)
|
|
throw new InvalidOperationException("The observable can only be subscribed once.");
|
|
|
|
_observer = observer;
|
|
observer.OnNext(_value);
|
|
return this;
|
|
}
|
|
|
|
public void Dispose() => _observer = null;
|
|
public void OnNext(T? value) => _observer?.OnNext(value);
|
|
|
|
public void PublishCompleted()
|
|
{
|
|
_observer?.OnCompleted();
|
|
_observer = null;
|
|
}
|
|
|
|
protected void PublishError(Exception error)
|
|
{
|
|
_observer?.OnError(error);
|
|
_observer = null;
|
|
}
|
|
}
|
|
}
|
|
|