public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
switch (target_type.BuiltinType) {
case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, Location);
case BuiltinTypeSpec.Type.UInt:
return new UIntConstant (target_type, (uint) Value, Location);
case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (target_type, (ulong) Value, Location);
case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
return null;
}