Mono.CSharp.Constant.ConvertImplicitly C# (CSharp) Method

ConvertImplicitly() public method

public ConvertImplicitly ( System.TypeSpec type ) : Constant
type System.TypeSpec
return Constant
		public virtual Constant ConvertImplicitly (TypeSpec type)
		{
			if (this.type == type)
				return this;

			if (!Convert.ImplicitNumericConversionExists (this.type, type))
				return null;

			bool fail;			
			object constant_value = ChangeType (GetValue (), type, out fail);
			if (fail){
				//
				// We should always catch the error before this is ever
				// reached, by calling Convert.ImplicitStandardConversionExists
				//
				throw new InternalErrorException ("Missing constant conversion between `{0}' and `{1}'",
				 Type.GetSignatureForError (), type.GetSignatureForError ());
			}

			return CreateConstantFromValue (type, constant_value, loc);
		}

Usage Example

Example #1
0
File: const.cs Project: mdae/MonoRT
        protected virtual Constant DoResolveValue(ResolveContext ec)
        {
            Constant value = initializer.ResolveAsConstant(ec, this);

            if (value == null)
            {
                return(null);
            }

            Constant c = value.ConvertImplicitly(MemberType);

            if (c == null)
            {
                if (TypeManager.IsReferenceType(MemberType))
                {
                    Error_ConstantCanBeInitializedWithNullOnly(MemberType, Location, GetSignatureForError(), Report);
                }
                else
                {
                    value.Error_ValueCannotBeConverted(ec, Location, MemberType, false);
                }
            }

            return(c);
        }
All Usage Examples Of Mono.CSharp.Constant::ConvertImplicitly