<PackageReference Include="System.Reactive" Version="6.0.0-preview.1" />
MaxDecimal
using System.
Runtime.
CompilerServices;
namespace System.
Reactive.
Linq.
ObservableImpl
{
[
System.
Runtime.
CompilerServices.
NullableContext(
1)]
[
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
0,
1
})]
internal sealed class MaxDecimal :
Producer<
decimal,
MaxDecimal.
_>
{
[
System.
Runtime.
CompilerServices.
NullableContext(
0)]
internal sealed class _ :
IdentitySink<
decimal>
{
private bool _hasValue;
private decimal _lastValue;
[
System.
Runtime.
CompilerServices.
NullableContext(
1)]
public _(
IObserver<
decimal>
observer)
:
base(
observer)
{
}
public override void OnNext(
decimal value)
{
if (
_hasValue) {
if (
value >
_lastValue)
_lastValue =
value;
}
else {
_lastValue =
value;
_hasValue =
true;
}
}
public override void OnCompleted()
{
if (!
_hasValue)
try {
throw new InvalidOperationException(
Strings_Linq.
NO_ELEMENTS);
}
catch (
Exception error) {
ForwardOnError(
error);
}
else {
ForwardOnNext(
_lastValue);
ForwardOnCompleted();
}
}
}
private readonly IObservable<
decimal>
_source;
public MaxDecimal(
IObservable<
decimal>
source)
{
_source =
source;
}
protected override _ CreateSink(
IObserver<
decimal>
observer)
{
return new _(
observer);
}
protected override void Run(
_ sink)
{
sink.
Run(
_source);
}
}
}