Mono.CSharp.FloatConstant.ConvertExplicitly C# (CSharp) Method

ConvertExplicitly() public method

public ConvertExplicitly ( bool in_checked_context, System.TypeSpec target_type ) : Constant
in_checked_context bool
target_type System.TypeSpec
return Constant
		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 || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new ByteConstant (target_type, (byte) DoubleValue, Location);
			case BuiltinTypeSpec.Type.SByte:
				if (in_checked_context) {
					if (Value < sbyte.MinValue || Value > sbyte.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new SByteConstant (target_type, (sbyte) DoubleValue, Location);
			case BuiltinTypeSpec.Type.Short:
				if (in_checked_context) {
					if (Value < short.MinValue || Value > short.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new ShortConstant (target_type, (short) DoubleValue, Location);
			case BuiltinTypeSpec.Type.UShort:
				if (in_checked_context) {
					if (Value < ushort.MinValue || Value > ushort.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new UShortConstant (target_type, (ushort) DoubleValue, Location);
			case BuiltinTypeSpec.Type.Int:
				if (in_checked_context) {
					if (Value < int.MinValue || Value > int.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new IntConstant (target_type, (int) DoubleValue, Location);
			case BuiltinTypeSpec.Type.UInt:
				if (in_checked_context) {
					if (Value < uint.MinValue || Value > uint.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new UIntConstant (target_type, (uint) DoubleValue, Location);
			case BuiltinTypeSpec.Type.Long:
				if (in_checked_context) {
					if (Value < long.MinValue || Value > long.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new LongConstant (target_type, (long) DoubleValue, Location);
			case BuiltinTypeSpec.Type.ULong:
				if (in_checked_context) {
					if (Value < ulong.MinValue || Value > ulong.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new ULongConstant (target_type, (ulong) DoubleValue, Location);
			case BuiltinTypeSpec.Type.Double:
				return new DoubleConstant (target_type, DoubleValue, Location);
			case BuiltinTypeSpec.Type.Char:
				if (in_checked_context) {
					if (Value < (float) char.MinValue || Value > (float) char.MaxValue || float.IsNaN (Value))
						throw new OverflowException ();
				}
				return new CharConstant (target_type, (char) DoubleValue, Location);
			case BuiltinTypeSpec.Type.Decimal:
				return new DecimalConstant (target_type, (decimal) DoubleValue, Location);
			}

			return null;
		}