using System; using System.Collections.Generic; using System.Text; 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 = BitConverter.SingleToInt32Bits(x); int yi = BitConverter.SingleToInt32Bits(y); int zi = xi ^ yi; return BitConverter.Int32BitsToSingle(zi); }; 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"); } } }