Expression SwitchGoverningType (ResolveContext ec, Expression expr)
{
TypeSpec t = expr.Type;
if (t == TypeManager.byte_type ||
t == TypeManager.sbyte_type ||
t == TypeManager.ushort_type ||
t == TypeManager.short_type ||
t == TypeManager.uint32_type ||
t == TypeManager.int32_type ||
t == TypeManager.uint64_type ||
t == TypeManager.int64_type ||
t == TypeManager.char_type ||
t == TypeManager.string_type ||
t == TypeManager.bool_type ||
TypeManager.IsEnumType (t))
return expr;
if (allowed_types == null){
allowed_types = new TypeSpec [] {
TypeManager.sbyte_type,
TypeManager.byte_type,
TypeManager.short_type,
TypeManager.ushort_type,
TypeManager.int32_type,
TypeManager.uint32_type,
TypeManager.int64_type,
TypeManager.uint64_type,
TypeManager.char_type,
TypeManager.string_type
};
}
//
// Try to find a *user* defined implicit conversion.
//
// If there is no implicit conversion, or if there are multiple
// conversions, we have to report an error
//
Expression converted = null;
foreach (TypeSpec tt in allowed_types){
Expression e;
e = Convert.ImplicitUserConversion (ec, expr, tt, loc);
if (e == null)
continue;
//
// Ignore over-worked ImplicitUserConversions that do
// an implicit conversion in addition to the user conversion.
//
if (!(e is UserCast))
continue;
if (converted != null){
ec.Report.ExtraInformation (loc, "(Ambiguous implicit user defined conversion in previous ");
return null;
}
converted = e;
}
return converted;
}