Consumer<T>
Represents typed function pointer implementing IConsumer<T>.
using DotNext.Runtime.CompilerServices;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace DotNext
{
[StructLayout(LayoutKind.Auto)]
[NullableContext(1)]
[Nullable(0)]
[CLSCompliant(false)]
public readonly struct Consumer<[Nullable(2)] T> : IConsumer<T>, IFunctional<Action<T>>
{
private readonly IntPtr ptr;
public unsafe bool IsEmpty => ptr == (IntPtr)(void*)null;
public unsafe Consumer([Nullable(new byte[] {
0,
1
})] IntPtr ptr)
{
if (ptr == (IntPtr)(void*)null)
throw new ArgumentNullException("ptr");
this.ptr = ptr;
}
void IConsumer<T>.Invoke(T arg)
{
IntPtr intPtr = ptr;
;
}
public Action<T> ToDelegate()
{
return DelegateHelpers.CreateDelegate<T>(ptr);
}
public unsafe override string ToString()
{
return new IntPtr((void*)(long)ptr).ToString("X");
}
public static implicit operator Consumer<T>([Nullable(new byte[] {
0,
1
})] IntPtr ptr)
{
return new Consumer<T>(ptr);
}
public static explicit operator Action<T>([Nullable(new byte[] {
0,
1
})] Consumer<T> consumer)
{
return consumer.ToDelegate();
}
}
}