本文整理汇总了C#中Expression.Error_ValueCannotBeConverted方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Error_ValueCannotBeConverted方法的具体用法?C# Expression.Error_ValueCannotBeConverted怎么用?C# Expression.Error_ValueCannotBeConverted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.Error_ValueCannotBeConverted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, target_type, true);
return null;
}
示例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.LiftedConversion (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 TypeSpec.IsReferenceType (expr.Type) ? new UnboxCast (expr, target_type) : 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, target_type, true);
return null;
}
示例3: 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, target_type, false);
return null;
}