Mono.CSharp.SByteConstant.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 && Value < 0)
					throw new OverflowException ();
				return new ByteConstant (target_type, (byte) Value, Location);
			case BuiltinTypeSpec.Type.Short:
				return new ShortConstant (target_type, (short) Value, Location);
			case BuiltinTypeSpec.Type.UShort:
				if (in_checked_context && Value < 0)
					throw new OverflowException ();
				return new UShortConstant (target_type, (ushort) Value, Location);
			case BuiltinTypeSpec.Type.Int:
				return new IntConstant (target_type, (int) Value, Location);
			case BuiltinTypeSpec.Type.UInt:
				if (in_checked_context && Value < 0)
					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 && Value < 0)
					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;
		}