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

TryReduceConstant() private method

private TryReduceConstant ( ResolveContext ec, System.TypeSpec target_type ) : Constant
ec ResolveContext
target_type System.TypeSpec
return Constant
		Constant TryReduceConstant (ResolveContext ec, TypeSpec target_type)
		{
			if (Type == target_type) {
				//
				// Reducing literal value produces a new constant. Syntactically 10 is not same as (int)10 
				//
				if (IsLiteral)
					return CreateConstantFromValue (target_type, GetValue (), loc);

				return this;
			}

			Constant c;
			if (target_type.IsEnum) {
				c = TryReduceConstant (ec, EnumSpec.GetUnderlyingType (target_type));
				if (c == null)
					return null;

				return new EnumConstant (c, target_type);
			}

			return ConvertExplicitly (ec.ConstantCheckState, target_type);
		}