Author: miguel
Date: 2007-03-07 11:41:21 -0500 (Wed, 07 Mar 2007)
New Revision: 73891

Modified:
   trunk/mcs/mcs/convert.cs
Log:
Reapply

Modified: trunk/mcs/mcs/convert.cs
===================================================================
--- trunk/mcs/mcs/convert.cs    2007-03-07 16:18:35 UTC (rev 73890)
+++ trunk/mcs/mcs/convert.cs    2007-03-07 16:41:21 UTC (rev 73891)
@@ -86,6 +86,33 @@
                        return false;
 #endif
                }
+               
+               static bool IList_To_Array(Type list, Type array)
+               {
+# if GMCS_SOURCE
+                       if (!list.IsGenericType || !array.IsArray || 
array.GetArrayRank() != 1)
+                               return false;
+                       
+                       Type gt = list.GetGenericTypeDefinition();
+                       if (gt != TypeManager.generic_ilist_type &&
+                               gt != TypeManager.generic_icollection_type &&
+                               gt != TypeManager.generic_ienumerable_type)
+                               return false;
+                       
+                       Type arg_type = TypeManager.GetTypeArguments(list)[0];
+                       Type element_type = TypeManager.GetElementType(array);
+                       
+                       if (element_type == arg_type)
+                               return true;
+                       
+                       if (MyEmptyExpr == null)
+                               MyEmptyExpr = new EmptyExpression();
+                       MyEmptyExpr.SetType(element_type);
+                       return ImplicitReferenceConversionExists(MyEmptyExpr, 
arg_type) || ExplicitReferenceConversionExists(element_type, arg_type);
+#else
+                       return false;
+#endif
+               }
 
                static Expression ImplicitTypeParameterConversion (Expression 
expr,
                                                                   Type 
target_type)
@@ -1692,6 +1719,9 @@
                                return true;
 
 
+                       if (source_type.IsInterface && IList_To_Array 
(source_type, target_type))
+                               return true;
+
                        // From an array type S with an element type Se to an 
array type T with an
                        // element type Te provided all the following are true:
                        //     * S and T differe only in element type, in other 
words, S and T
@@ -1814,6 +1844,13 @@
                                                return new UnboxCast (source, 
target_type);
                                }
 
+                               //
+                               // From System.Collecitons.Generic.IList<T> and 
its base interfaces to a one-dimensional
+                               // array type S[], provided there is an 
implicit or explicit reference conversion from S to T.
+                               //
+                               if (IList_To_Array(source_type, target_type))
+                                       return new EmptyCast(source, 
target_type);
+
                                return null;
                        }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to