using System; namespace Capnp { class PrimitiveCoder { class Coder { public static Func? Fn { get; set; } } static PrimitiveCoder() { Coder.Fn = (x, y) => x != y; Coder.Fn = (x, y) => (sbyte)(x ^ y); Coder.Fn = (x, y) => (byte)(x ^ y); Coder.Fn = (x, y) => (short)(x ^ y); Coder.Fn = (x, y) => (ushort)(x ^ y); Coder.Fn = (x, y) => x ^ y; Coder.Fn = (x, y) => x ^ y; Coder.Fn = (x, y) => x ^ y; Coder.Fn = (x, y) => x ^ y; Coder.Fn = (x, y) => { int xi = x.ReplacementSingleToInt32Bits(); int yi = y.ReplacementSingleToInt32Bits(); int zi = xi ^ yi; return BitConverter.ToSingle(BitConverter.GetBytes(zi), 0); }; Coder.Fn = (x, y) => { long xi = BitConverter.DoubleToInt64Bits(x); long yi = BitConverter.DoubleToInt64Bits(y); long zi = xi ^ yi; return BitConverter.Int64BitsToDouble(zi); }; } public static Func Get() { return Coder.Fn ?? throw new NotSupportedException("Generic type argument is not a supported primitive type, no coder defined"); } } }