DelegatingConverter<TInput, TOutput>
struct DelegatingConverter<TInput, TOutput> : ISupplier<TInput, TOutput>, IFunctional<Func<TInput, TOutput>>, IFunctional<Converter<TInput, TOutput>>
using DotNext.Runtime.CompilerServices;
using System;
using System.Runtime.InteropServices;
namespace DotNext
{
[StructLayout(LayoutKind.Auto)]
internal readonly struct DelegatingConverter<TInput, TOutput> : ISupplier<TInput, TOutput>, IFunctional<Func<TInput, TOutput>>, IFunctional<Converter<TInput, TOutput>>
{
private readonly Converter<TInput, TOutput> converter;
internal DelegatingConverter(Converter<TInput, TOutput> converter)
{
if (converter == null)
throw new ArgumentNullException("converter");
this.converter = converter;
}
TOutput ISupplier<TInput, TOutput>.Invoke(TInput arg)
{
return converter(arg);
}
Func<TInput, TOutput> IFunctional<Func<TInput, TOutput>>.ToDelegate()
{
return DelegateHelpers.ChangeType<Func<TInput, TOutput>>((Delegate)converter);
}
Converter<TInput, TOutput> IFunctional<Converter<TInput, TOutput>>.ToDelegate()
{
return converter;
}
public static implicit operator DelegatingConverter<TInput, TOutput>(Converter<TInput, TOutput> converter)
{
return new DelegatingConverter<TInput, TOutput>(converter);
}
}
}