Mono.CSharp.IntConstant.TryImplicitIntConversion C# (CSharp) Method

TryImplicitIntConversion() private method

Attempts to perform an implicit constant conversion of the IntConstant into a different data type using casts (See Implicit Constant Expression Conversions)
private TryImplicitIntConversion ( System.TypeSpec target_type ) : Constant
target_type System.TypeSpec
return Constant
		Constant TryImplicitIntConversion (TypeSpec target_type)
		{
			switch (target_type.BuiltinType) {
			case BuiltinTypeSpec.Type.SByte:
				if (Value >= SByte.MinValue && Value <= SByte.MaxValue)
					return new SByteConstant (target_type, (sbyte) Value, loc);
				break;
			case BuiltinTypeSpec.Type.Byte:
				if (Value >= Byte.MinValue && Value <= Byte.MaxValue)
					return new ByteConstant (target_type, (byte) Value, loc);
				break;
			case BuiltinTypeSpec.Type.Short:
				if (Value >= Int16.MinValue && Value <= Int16.MaxValue)
					return new ShortConstant (target_type, (short) Value, loc);
				break;
			case BuiltinTypeSpec.Type.UShort:
				if (Value >= UInt16.MinValue && Value <= UInt16.MaxValue)
					return new UShortConstant (target_type, (ushort) Value, loc);
				break;
			case BuiltinTypeSpec.Type.UInt:
				if (Value >= 0)
					return new UIntConstant (target_type, (uint) Value, loc);
				break;
			case BuiltinTypeSpec.Type.ULong:
				//
				// we can optimize this case: a positive int32
				// always fits on a uint64.  But we need an opcode
				// to do it.
				//
				if (Value >= 0)
					return new ULongConstant (target_type, (ulong) Value, loc);
				break;
			case BuiltinTypeSpec.Type.Double:
				return new DoubleConstant (target_type, (double) Value, loc);
			case BuiltinTypeSpec.Type.Float:
				return new FloatConstant (target_type, (float) Value, loc);
			}

			return null;
		}
	}