Ejemplo n.º 1
0
        public static bool IsConvertible(IType type, IType dstType)
        {
            if (!type.CanAssignTo(dstType))
            {
                if (type.CanPromoteTo(dstType))
                {
                    return(true);
                }

                /*
                 * else if (type.CanImplicitlyCastTo(dstType))
                 *  return true;
                 */
                else if ((dstType.IsEqualTo(Types.GetType("Object")) || dstType.IsEqualTo(Types.GetType("ValueType"))) && (type is ValueTypeSymbol))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
 public static bool IsDelegate(IType type)
 {
     return(type.IsInstanceOf(Types.GetType("MulticastDelegate")));
 }
Ejemplo n.º 3
0
        public static bool SetType(ref Expression expr, IType dstType, IContext context)
        {
            IType type = expr.EvalType;

            if (!type.CanAssignTo(dstType))
            {
                if (type.CanPromoteTo(dstType))
                {
                    expr = new TypePromotionExpression(expr, new ResolvedType(dstType));
                    expr = expr.ResolveRValue(context);
                }

                /*
                 * else if (type.CanImplicitlyCastTo(dstType))
                 * {
                 * }
                 */
                else if ((dstType.IsEqualTo(Types.GetType("Object")) || dstType.IsEqualTo(Types.GetType("ValueType"))) && (type is ValueTypeSymbol))
                {
                    expr = new BoxExpression(expr);
                    expr = expr.ResolveRValue(context);
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }