Mono.CSharp.IntConstant.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)
						throw new OverflowException ();
				}
				return new ByteConstant (target_type, (byte) Value, Location);
			case BuiltinTypeSpec.Type.SByte:
				if (in_checked_context) {
					if (Value < SByte.MinValue || 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.MinValue || Value > Int16.MaxValue)
						throw new OverflowException ();
				}
				return new ShortConstant (target_type, (short) Value, Location);
			case BuiltinTypeSpec.Type.UShort:
				if (in_checked_context) {
					if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
						throw new OverflowException ();
				}
				return new UShortConstant (target_type, (ushort) Value, Location);
			case BuiltinTypeSpec.Type.UInt:
				if (in_checked_context) {
					if (Value < UInt32.MinValue)
						throw new OverflowException ();
				}
				return new UIntConstant (target_type, (uint) Value, Location);
			case BuiltinTypeSpec.Type.Long:
				return new LongConstant (target_type, (long) Value, Location);
			case BuiltinTypeSpec.Type.ULong:
				if (in_checked_context && Value < 0)
					throw new OverflowException ();
				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.Char:
				if (in_checked_context) {
					if (Value < Char.MinValue || Value > Char.MaxValue)
						throw new OverflowException ();
				}
				return new CharConstant (target_type, (char) Value, Location);
			case BuiltinTypeSpec.Type.Decimal:
				return new DecimalConstant (target_type, (decimal) Value, Location);
			}

			return null;
		}