當前位置: 首頁>>代碼示例>>C#>>正文


C# Expression.Error_ValueCannotBeConverted方法代碼示例

本文整理匯總了C#中Mono.CSharp.Expression.Error_ValueCannotBeConverted方法的典型用法代碼示例。如果您正苦於以下問題:C# Expression.Error_ValueCannotBeConverted方法的具體用法?C# Expression.Error_ValueCannotBeConverted怎麽用?C# Expression.Error_ValueCannotBeConverted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.CSharp.Expression的用法示例。


在下文中一共展示了Expression.Error_ValueCannotBeConverted方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExplicitConversionStandard

		/// <summary>
		///   Same as ExplicitConversion, only it doesn't include user defined conversions
		/// </summary>
		static public Expression ExplicitConversionStandard (ResolveContext ec, Expression expr,
								     TypeSpec target_type, Location l)
		{
			int errors = ec.Report.Errors;
			Expression ne = ImplicitConversionStandard (ec, expr, target_type, l);
			if (ec.Report.Errors > errors)
				return null;

			if (ne != null)
				return ne;

			ne = ExplicitNumericConversion (ec, expr, target_type);
			if (ne != null)
				return ne;

			ne = ExplicitReferenceConversion (expr, expr.Type, target_type);
			if (ne != null)
				return ne;

			if (ec.IsUnsafe && expr.Type.IsPointer && target_type.IsPointer && ((PointerContainer)expr.Type).Element.Kind == MemberKind.Void)
				return EmptyCast.Create (expr, target_type);

			expr.Error_ValueCannotBeConverted (ec, l, target_type, true);
			return null;
		}
開發者ID:nylen,項目名稱:SharpDevelop,代碼行數:28,代碼來源:convert.cs

示例2: ExplicitConversion

		/// <summary>
		///   Performs an explicit conversion of the expression `expr' whose
		///   type is expr.Type to `target_type'.
		/// </summary>
		static public Expression ExplicitConversion (ResolveContext ec, Expression expr,
			TypeSpec target_type, Location loc)
		{
			Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
			if (e != null) {
				//
				// Don't eliminate explicit precission casts
				//
				if (e == expr) {
					if (target_type.BuiltinType == BuiltinTypeSpec.Type.Float)
						return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
					
					if (target_type.BuiltinType == BuiltinTypeSpec.Type.Double)
						return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
				}
					
				return e;
			}

			TypeSpec expr_type = expr.Type;
			if (target_type.IsNullableType) {
				TypeSpec target;

				if (expr_type.IsNullableType) {
					target = Nullable.NullableInfo.GetUnderlyingType (target_type);
					Expression unwrap = Nullable.Unwrap.Create (expr);
					e = ExplicitConversion (ec, unwrap, target, expr.Location);
					if (e == null)
						return null;

					return new Nullable.Lifted (e, unwrap, target_type).Resolve (ec);
				}
				if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Object) {
					return new UnboxCast (expr, target_type);
				}

				target = TypeManager.GetTypeArguments (target_type) [0];
				e = ExplicitConversionCore (ec, expr, target, loc);
				if (e != null)
					return Nullable.Wrap.Create (e, target_type);
			} else if (expr_type.IsNullableType) {
				e = ImplicitBoxingConversion (expr, Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type);
				if (e != null)
					return e;

				e = Nullable.Unwrap.Create (expr, false);			
				e = ExplicitConversionCore (ec, e, target_type, loc);
				if (e != null)
					return EmptyCast.Create (e, target_type);
			}
			
			e = ExplicitUserConversion (ec, expr, target_type, loc);
			if (e != null)
				return e;			

			expr.Error_ValueCannotBeConverted (ec, loc, target_type, true);
			return null;
		}
開發者ID:nylen,項目名稱:SharpDevelop,代碼行數:62,代碼來源:convert.cs

示例3: ResolveInitializer

		protected override Expression ResolveInitializer (BlockContext bc, LocalVariable li, Expression initializer)
		{
			initializer = initializer.Resolve (bc);
			if (initializer == null)
				return null;

			var c = initializer as Constant;
			if (c == null) {
				initializer.Error_ExpressionMustBeConstant (bc, initializer.Location, li.Name);
				return null;
			}

			c = c.ConvertImplicitly (bc, li.Type);
			if (c == null) {
				if (TypeManager.IsReferenceType (li.Type))
					initializer.Error_ConstantCanBeInitializedWithNullOnly (bc, li.Type, initializer.Location, li.Name);
				else
					initializer.Error_ValueCannotBeConverted (bc, initializer.Location, li.Type, false);

				return null;
			}

			li.ConstantValue = c;
			return initializer;
		}
開發者ID:alisci01,項目名稱:mono,代碼行數:25,代碼來源:statement.cs

示例4: ImplicitConversionRequired

		/// <summary>
		///   Attempts to implicitly convert `source' into `target_type', using
		///   ImplicitConversion.  If there is no implicit conversion, then
		///   an error is signaled
		/// </summary>
		static public Expression ImplicitConversionRequired (ResolveContext ec, Expression source,
								     TypeSpec target_type, Location loc)
		{
			Expression e = ImplicitConversion (ec, source, target_type, loc);
			if (e != null)
				return e;

			source.Error_ValueCannotBeConverted (ec, loc, target_type, false);
			return null;
		}
開發者ID:nylen,項目名稱:SharpDevelop,代碼行數:15,代碼來源:convert.cs

示例5: ImplicitConversionRequired

        /// <summary>
        ///   Attempts to implicitly convert `source' into `target_type', using
        ///   ImplicitConversion.  If there is no implicit conversion, then
        ///   an error is signaled
        /// </summary>
        public static Expression ImplicitConversionRequired(ResolveContext ec, Expression source,
            TypeSpec target_type, Location loc)
        {
            Expression e = ImplicitConversion (ec, source, target_type, loc);
            if (e != null)
                return e;

            if (source.Type == InternalType.Dynamic) {
                Arguments args = new Arguments (1);
                args.Add (new Argument (source));
                return new DynamicConversion (target_type, 0, args, loc).Resolve (ec);
            }

            source.Error_ValueCannotBeConverted (ec, loc, target_type, false);
            return null;
        }
開發者ID:speier,項目名稱:shake,代碼行數:21,代碼來源:convert.cs

示例6: ConvertExpressionToArrayIndex

        //
        // Converts `source' to an int, uint, long or ulong.
        //
        protected Expression ConvertExpressionToArrayIndex(ResolveContext ec, Expression source)
        {
            if (source.type == InternalType.Dynamic) {
                Arguments args = new Arguments (1);
                args.Add (new Argument (source));
                return new DynamicConversion (TypeManager.int32_type, CSharpBinderFlags.ConvertArrayIndex, args, loc).Resolve (ec);
            }

            Expression converted;

            using (ec.Set (ResolveContext.Options.CheckedScope)) {
                converted = Convert.ImplicitConversion (ec, source, TypeManager.int32_type, source.loc);
                if (converted == null)
                    converted = Convert.ImplicitConversion (ec, source, TypeManager.uint32_type, source.loc);
                if (converted == null)
                    converted = Convert.ImplicitConversion (ec, source, TypeManager.int64_type, source.loc);
                if (converted == null)
                    converted = Convert.ImplicitConversion (ec, source, TypeManager.uint64_type, source.loc);

                if (converted == null) {
                    source.Error_ValueCannotBeConverted (ec, source.loc, TypeManager.int32_type, false);
                    return null;
                }
            }

            //
            // Only positive constants are allowed at compile time
            //
            Constant c = converted as Constant;
            if (c != null && c.IsNegative)
                Error_NegativeArrayIndex (ec, source.loc);

            // No conversion needed to array index
            if (converted.Type == TypeManager.int32_type)
                return converted;

            return new ArrayIndexCast (converted).Resolve (ec);
        }
開發者ID:speier,項目名稱:shake,代碼行數:41,代碼來源:ecore.cs

示例7: ExplicitConversionStandard

        /// <summary>
        ///   Same as ExplicitConversion, only it doesn't include user defined conversions
        /// </summary>
        public static Expression ExplicitConversionStandard(ResolveContext ec, Expression expr,
            TypeSpec target_type, Location l)
        {
            int errors = ec.Report.Errors;
            Expression ne = ImplicitConversionStandard (ec, expr, target_type, l);
            if (ec.Report.Errors > errors)
                return null;

            if (ne != null)
                return ne;

            ne = ExplicitNumericConversion (expr, target_type);
            if (ne != null)
                return ne;

            ne = ExplicitReferenceConversion (expr, expr.Type, target_type);
            if (ne != null)
                return ne;

            if (ec.IsUnsafe && expr.Type == TypeManager.void_ptr_type && target_type.IsPointer)
                return EmptyCast.Create (expr, target_type);

            expr.Error_ValueCannotBeConverted (ec, l, target_type, true);
            return null;
        }
開發者ID:speier,項目名稱:shake,代碼行數:28,代碼來源:convert.cs

示例8: ResolveBoolean

		/// <summary>
		///   Resolves the expression `e' into a boolean expression: either through
		///   an implicit conversion, or through an `operator true' invocation
		/// </summary>
		public static Expression ResolveBoolean (EmitContext ec, Expression e, Location loc)
		{
			e = e.Resolve (ec);
			if (e == null)
				return null;

			if (e.Type == TypeManager.bool_type)
				return e;

			Expression converted = Convert.ImplicitConversion (ec, e, TypeManager.bool_type, Location.Null);

			if (converted != null)
				return converted;

			//
			// If no implicit conversion to bool exists, try using `operator true'
			//
			converted = Expression.GetOperatorTrue (ec, e, loc);
			if (converted == null){
				e.Error_ValueCannotBeConverted (ec, loc, TypeManager.bool_type, false);
				return null;
			}
			return converted;
		}
開發者ID:lewurm,項目名稱:benchmarker,代碼行數:28,代碼來源:ecore.cs

示例9: ConvertExpressionToArrayIndex

		//
		// Converts `source' to an int, uint, long or ulong.
		//
		public Expression ConvertExpressionToArrayIndex (EmitContext ec, Expression source)
		{
			Expression converted;
			
			using (ec.With (EmitContext.Flags.CheckState, true)) {
				converted = Convert.ImplicitConversion (ec, source, TypeManager.int32_type, source.loc);
				if (converted == null)
					converted = Convert.ImplicitConversion (ec, source, TypeManager.uint32_type, source.loc);
				if (converted == null)
					converted = Convert.ImplicitConversion (ec, source, TypeManager.int64_type, source.loc);
				if (converted == null)
					converted = Convert.ImplicitConversion (ec, source, TypeManager.uint64_type, source.loc);

				if (converted == null) {
					source.Error_ValueCannotBeConverted (ec, source.loc, TypeManager.int32_type, false);
					return null;
				}
			}

			//
			// Only positive constants are allowed at compile time
			//
			Constant c = converted as Constant;
			if (c != null) {
				if (c.IsNegative) {
					Error_NegativeArrayIndex (source.loc);
				}
				return c;
			}

			return new ArrayIndexCast (converted).Resolve (ec);
		}
開發者ID:lewurm,項目名稱:benchmarker,代碼行數:35,代碼來源:ecore.cs

示例10: ResolveBoolean

		/// <summary>
		///   Resolves the expression `e' into a boolean expression: either through
		///   an implicit conversion, or through an `operator true' invocation
		/// </summary>
		public static Expression ResolveBoolean (ResolveContext ec, Expression e, Location loc)
		{
			e = e.Resolve (ec);
			if (e == null)
				return null;

			if (e.Type == TypeManager.bool_type)
				return e;

			if (TypeManager.IsDynamicType (e.Type)) {
				Arguments args = new Arguments (1);
				args.Add (new Argument (e));
				return new DynamicUnaryConversion ("IsTrue", args, loc).Resolve (ec);
			}

			Expression converted = Convert.ImplicitConversion (ec, e, TypeManager.bool_type, Location.Null);

			if (converted != null)
				return converted;

			//
			// If no implicit conversion to bool exists, try using `operator true'
			//
			converted = Expression.GetOperatorTrue (ec, e, loc);
			if (converted == null){
				e.Error_ValueCannotBeConverted (ec, loc, TypeManager.bool_type, false);
				return null;
			}
			return converted;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:34,代碼來源:ecore.cs

示例11: ExplicitConversion

		/// <summary>
		///   Performs an explicit conversion of the expression `expr' whose
		///   type is expr.Type to `target_type'.
		/// </summary>
		static public Expression ExplicitConversion (ResolveContext ec, Expression expr,
			Type target_type, Location loc)
		{
			Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
			if (e != null) {
				//
				// Don't eliminate explicit precission casts
				//
				if (e == expr) {
					if (target_type == TypeManager.float_type)
						return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
					
					if (target_type == TypeManager.double_type)
						return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
				}
					
				return e;
			}

			Type expr_type = expr.Type;
			if (TypeManager.IsNullableType (target_type)) {
				if (TypeManager.IsNullableType (expr_type)) {
					Type target = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (target_type)[0]);
					Expression unwrap = Nullable.Unwrap.Create (expr);
					e = ExplicitConversion (ec, unwrap, target, expr.Location);
					if (e == null)
						return null;

					return new Nullable.Lifted (e, unwrap, target_type).Resolve (ec);
				} else if (expr_type == TypeManager.object_type) {
					return new UnboxCast (expr, target_type);
				} else {
					Type target = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (target_type) [0]);

					e = ExplicitConversionCore (ec, expr, target, loc);
					if (e != null)
						return Nullable.Wrap.Create (e, target_type);
				}
			} else if (TypeManager.IsNullableType (expr_type)) {
				e = Nullable.Unwrap.Create (expr, false);

				bool use_class_cast;
				if (ImplicitBoxingConversionExists (e, target_type, out use_class_cast))
					return new BoxedCast (expr, target_type);
				
				e = ExplicitConversionCore (ec, e, target_type, loc);
				if (e != null)
					return EmptyCast.Create (e, target_type);
			}
			
			e = ExplicitUserConversion (ec, expr, target_type, loc);
			if (e != null)
				return e;			

			expr.Error_ValueCannotBeConverted (ec, loc, target_type, true);
			return null;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:61,代碼來源:convert.cs


注:本文中的Mono.CSharp.Expression.Error_ValueCannotBeConverted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。