网上演练
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.

45 lines
1.1 KiB

// Needed for NET40
#if !NET_4_6
using System;
using LinqInternal.Core;
namespace LinqInternal.Collections
{
[Serializable]
internal sealed class ConvertedObserver<TInput, TOutput> : IObserver<TInput>
{
private readonly Func<TInput, TOutput> _converter;
private readonly IObserver<TOutput> _observer;
public ConvertedObserver(IObserver<TOutput> observer, Func<TInput, TOutput> converter)
{
if (observer == null)
{
throw new ArgumentNullException("observer");
}
_observer = observer;
if (converter == null)
{
throw new ArgumentNullException("converter");
}
_converter = converter;
}
public void OnCompleted()
{
_observer.OnCompleted();
}
public void OnError(Exception error)
{
_observer.OnError(error);
}
public void OnNext(TInput value)
{
_observer.OnNext(_converter.Invoke(value));
}
}
}
#endif