private static Expression BigIntegerConstant(BigInteger value) {
int ival;
if (value.AsInt32(out ival)) {
return Expression.Call(
typeof(BigInteger).GetMethod("Create", new Type[] { typeof(int) }),
Expression.Constant(ival)
);
}
long lval;
if (value.AsInt64(out lval)) {
return Expression.Call(
typeof(BigInteger).GetMethod("Create", new Type[] { typeof(long) }),
Expression.Constant(lval)
);
}
return Expression.New(
typeof(BigInteger).GetConstructor(new Type[] { typeof(int), typeof(uint[]) }),
Expression.Constant((int)value.Sign),
CreateUIntArray(value.GetBits())
);
}