2004-03-29 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Mon, 29 Mar 2004 15:28:00 +0000 (15:28 -0000)
committerMartin Baulig <martin@novell.com>
Mon, 29 Mar 2004 15:28:00 +0000 (15:28 -0000)
* convert.cs: Use TypeManager.IsSubclassOf() instead of comparing
types directly to make it work for generic instances.

svn path=/trunk/mcs/; revision=24711

mcs/gmcs/ChangeLog
mcs/gmcs/convert.cs
mcs/gmcs/typemanager.cs

index b30481cafc83d332f9fd421015a2d45e47ba17be..db37cdaa4275726466dbdab38f211c19d753f989 100755 (executable)
@@ -1,3 +1,10 @@
+2004-03-29  Martin Baulig  <martin@ximian.com>
+
+       * convert.cs: Use TypeManager.IsSubclassOf() instead of comparing
+       types directly to make it work for generic instances.
+
+       * typemanager.cs (TypeManager.IsSubclassOf): New static method.
+
 2004-03-29  Martin Baulig  <martin@ximian.com>
 
        * typemanager.cs (TypeManager.MayBecomeEqualGenericTypes): Added
index 747ebed718ec2f008c9865abb2678722a21d66a5..f70eab18c2f8eab0ca46b1f432519abb4047ceca 100644 (file)
@@ -60,7 +60,7 @@ namespace Mono.CSharp {
                                        return new BoxedCast (expr);
                                if (expr is NullLiteral)
                                        return new NullCast (expr, target_type);
-                       } else if (expr_type.IsSubclassOf (target_type)) {
+                       } else if (TypeManager.IsSubclassOf (expr_type, target_type)) {
                                //
                                // Special case: enumeration to System.Enum.
                                // System.Enum is not a value type, it is a class, so we need
@@ -170,7 +170,7 @@ namespace Mono.CSharp {
                                if (expr_type.IsClass || TypeManager.IsValueType (expr_type) ||
                                    expr_type.IsInterface || expr_type == TypeManager.enum_type)
                                        return true;
-                       } else if (expr_type.IsSubclassOf (target_type)) 
+                       } else if (TypeManager.IsSubclassOf (expr_type, target_type)) 
                                return true;
                        else {
                                // Please remember that all code below actually comes
@@ -1427,14 +1427,14 @@ namespace Mono.CSharp {
                        //
                        // From any class S to any class-type T, provided S is a base class of T
                        //
-                       if (target_type.IsSubclassOf (source_type))
+                       if (TypeManager.IsSubclassOf (target_type, source_type))
                                return true;
 
                        //
                        // From any interface type S to any interface T provided S is not derived from T
                        //
                        if (source_type.IsInterface && target_type.IsInterface){
-                               if (!target_type.IsSubclassOf (source_type))
+                               if (!TypeManager.IsSubclassOf (target_type, source_type))
                                        return true;
                        }
                            
@@ -1525,7 +1525,7 @@ namespace Mono.CSharp {
                        //
                        // From any class S to any class-type T, provided S is a base class of T
                        //
-                       if (target_type.IsSubclassOf (source_type))
+                       if (TypeManager.IsSubclassOf (target_type, source_type))
                                return new ClassCast (source, target_type);
 
                        //
index 8d7dab4345296061a602858f81b9ae2d2f9e2fb8..73b5249301acb2480c3d1540a1b768749fff29c8 100755 (executable)
@@ -1716,6 +1716,14 @@ public class TypeManager {
                return false;
        }
 
+       public static bool IsSubclassOf (Type type, Type parent)
+       {
+               if (type.IsGenericInstance)
+                       type = type.GetGenericTypeDefinition ();
+
+               return type.IsSubclassOf (parent);
+       }
+
        //
        // Checks whether `type' is a subclass or nested child of `parent'.
        //