<PackageReference Include="System.Reactive" Version="6.0.0-preview.1" />
ElementAt<TSource>
using System.
Runtime.
CompilerServices;
namespace System.
Reactive.
Linq.
ObservableImpl
{
[
System.
Runtime.
CompilerServices.
NullableContext(
1)]
[
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
0,
1,
1,
1
})]
internal sealed class ElementAt<[
System.
Runtime.
CompilerServices.
Nullable(
2)]
TSource> :
Producer<
TSource,
ElementAt<
TSource>.
_>
{
[
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
0,
1
})]
internal sealed class _ :
IdentitySink<
TSource>
{
private int _i;
public _(
int index,
IObserver<
TSource>
observer)
:
base(
observer)
{
_i =
index;
}
public override void OnNext(
TSource value)
{
if (
_i ==
0) {
ForwardOnNext(
value);
ForwardOnCompleted();
}
_i--;
}
public override void OnCompleted()
{
if (
_i >=
0)
try {
throw new ArgumentOutOfRangeException(
"index");
}
catch (
Exception error) {
ForwardOnError(
error);
}
}
}
private readonly IObservable<
TSource>
_source;
private readonly int _index;
public ElementAt(
IObservable<
TSource>
source,
int index)
{
_source =
source;
_index =
index;
}
[
return:
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
1,
0
})]
protected override _ CreateSink(
IObserver<
TSource>
observer)
{
return new _(
_index,
observer);
}
protected override void Run([
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
1,
0
})]
_ sink)
{
sink.
Run(
_source);
}
}
}