Esempio n. 1
0
        public static bool ImplicitConversionExists(ScriptingContext context,
							     TargetType source, TargetType target)
        {
            if (source.Equals (target))
                return true;

            if ((source is TargetFundamentalType) && (target is TargetFundamentalType))
                return ImplicitFundamentalConversionExists (
                    context, (TargetFundamentalType) source,
                    (TargetFundamentalType) target);

            if ((source is TargetFundamentalType) && (target is TargetObjectType) &&
                (((TargetFundamentalType) source).FundamentalKind == FundamentalKind.String))
                return true;

            if ((source is TargetClassType) && (target is TargetClassType))
                return ImplicitReferenceConversionExists (
                    context, (TargetClassType) source,
                    (TargetClassType) target);

            return false;
        }
		public static bool ImplicitConversionExists (MdbEvaluationContext ctx,
							     TargetType source, TargetType target)
		{
			if (source.Equals (target))
				return true;
			
			if (source is TargetArrayType && target.Name == "System.Array")
				return true;

			if (ObjectUtil.FixTypeName (target.Name) == "System.Object")
				return true;
			
			if (source is TargetArrayType && target is TargetArrayType) {
				TargetArrayType sa = (TargetArrayType) source;
				TargetArrayType ta = (TargetArrayType) target;
				return sa.ElementType.Equals (ta.ElementType);
			}
			
			if (source is TargetEnumType) {
				TargetEnumType e = (TargetEnumType) source;
				if (ImplicitConversionExists (ctx, e.Value.Type, target))
					return true;
			}

			if (target is TargetEnumType) {
				TargetEnumType e = (TargetEnumType) target;
				if (ImplicitConversionExists (ctx, source, e.Value.Type))
					return true;
			}

			if ((source is TargetFundamentalType) && (target is TargetFundamentalType))
				return ImplicitFundamentalConversionExists (
					(TargetFundamentalType) source,
					(TargetFundamentalType) target);

			if ((source is TargetClassType) && (target is TargetClassType))
				return ImplicitReferenceConversionExists (
					ctx, (TargetClassType) source,
					(TargetClassType) target);

			return false;
		}