Author: martin
Date: 2005-03-17 05:30:22 -0500 (Thu, 17 Mar 2005)
New Revision: 41932

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/convert.cs
   trunk/mcs/gmcs/generic.cs
Log:
2005-03-17  Martin Baulig  <[EMAIL PROTECTED]>

        * generic.cs (TypeMananager.IsIEnumerable): New public method.

        * convert.cs (Convert.ImplicitReferenceConversion(Exists)): Allow
        converting from an array-type of T to `IEnumerable<T>'.



Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-03-17 10:03:13 UTC (rev 41931)
+++ trunk/mcs/gmcs/ChangeLog    2005-03-17 10:30:22 UTC (rev 41932)
@@ -1,3 +1,10 @@
+2005-03-17  Martin Baulig  <[EMAIL PROTECTED]>
+
+       * generic.cs (TypeMananager.IsIEnumerable): New public method.
+
+       * convert.cs (Convert.ImplicitReferenceConversion(Exists)): Allow
+       converting from an array-type of T to `IEnumerable<T>'.
+
 2005-03-16  Martin Baulig  <[EMAIL PROTECTED]>
 
        * generic.cs (Nullable.Unwrap): Implement IAssignMethod.

Modified: trunk/mcs/gmcs/convert.cs
===================================================================
--- trunk/mcs/gmcs/convert.cs   2005-03-17 10:03:13 UTC (rev 41931)
+++ trunk/mcs/gmcs/convert.cs   2005-03-17 10:30:22 UTC (rev 41932)
@@ -234,7 +234,7 @@
                                else
                                        return null;
                        }
-                               
+
                        // from an array-type S to an array-type of type T
                        if (expr_type.IsArray && target_type.IsArray) {
                                if (expr_type.GetArrayRank () == 
target_type.GetArrayRank ()) {
@@ -257,7 +257,11 @@
                        // from an array-type to System.Array
                        if (expr_type.IsArray && target_type == 
TypeManager.array_type)
                                return new EmptyCast (expr, target_type);
-                               
+
+                       // from an array-type of type T to IEnumerable<T>
+                       if (expr_type.IsArray && TypeManager.IsIEnumerable 
(expr_type, target_type))
+                               return new EmptyCast (expr, target_type);
+
                        // from any delegate type to System.Delegate
                        if ((expr_type == TypeManager.delegate_type || 
TypeManager.IsDelegateType (expr_type)) &&
                            target_type == TypeManager.delegate_type)
@@ -346,7 +350,11 @@
                        // from an array-type to System.Array
                        if (expr_type.IsArray && (target_type == 
TypeManager.array_type))
                                return true;
-                               
+
+                       // from an array-type of type T to IEnumerable<T>
+                       if (expr_type.IsArray && TypeManager.IsIEnumerable 
(expr_type, target_type))
+                               return true;
+
                        // from any delegate type to System.Delegate
                        if ((expr_type == TypeManager.delegate_type || 
TypeManager.IsDelegateType (expr_type)) &&
                            target_type == TypeManager.delegate_type)

Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2005-03-17 10:03:13 UTC (rev 41931)
+++ trunk/mcs/gmcs/generic.cs   2005-03-17 10:30:22 UTC (rev 41932)
@@ -1756,6 +1756,22 @@
                                return t.GetGenericArguments ();
                }
 
+               //
+               // Whether `array' is an array of T and `enumerator' is 
`IEnumerable<T>'.
+               // For instance "string[]" -> "IEnumerable<string>".
+               //
+               public static bool IsIEnumerable (Type array, Type enumerator)
+               {
+                       if (!array.IsArray || !enumerator.IsGenericInstance)
+                               return false;
+
+                       if (enumerator.GetGenericTypeDefinition () != 
generic_ienumerable_type)
+                               return false;
+
+                       Type[] args = GetTypeArguments (enumerator);
+                       return args [0] == GetElementType (array);
+               }
+
                public static bool IsEqual (Type a, Type b)
                {
                        if (a.Equals (b))

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

Reply via email to