public static object FFIConvertFrom <T>(T value) { var tc = Type.GetTypeCode(typeof(T)); switch (tc) { case TypeCode.Int32: case TypeCode.Double: return(value); case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: return(Builtins.ToIntegerIfPossible(GetValue(value))); case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Byte: case TypeCode.SByte: return(Convert.ToInt32(value)); case TypeCode.Single: return(Convert.ToDouble(value)); case TypeCode.String: return(Convert.ToString(value)); default: if (typeof(T) == typeof(IntPtr) || typeof(T) == typeof(UIntPtr)) { return(value); } return(Builtins.AssertionViolation("FFIConvertTo", "not a known ffi type", value, typeof(T))); } }
// helper public static object LongToBignum(long l) { return(Builtins.ToIntegerIfPossible(new BigInteger(l))); }