2009-07-08 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Wed, 8 Jul 2009 21:45:36 +0000 (21:45 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 8 Jul 2009 21:45:36 +0000 (21:45 -0000)
* DerivedTypes.cs: Refactor the types here to move
a lot of code to the base DerivedType in preparation
for upcomming ByRefType and PointerType puppies.

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

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/DerivedTypes.cs

index 5c13ccdb000e103698fc74d44a0fee6a6dd80ab6..e23177d720cbc830c244a252a130a583954c04e8 100644 (file)
@@ -1,3 +1,9 @@
+2009-07-08 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * DerivedTypes.cs: Refactor the types here to move
+       a lot of code to the base DerivedType in preparation
+       for upcomming ByRefType and PointerType puppies.
+
 2009-07-07 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * TypeBuilder.cs (IsArrayImpl): Return false always as a
index 37237f7ec826326d4d287869cd9163b1343c8a3a..d82608b51e4ceb356f46ab640c36a6399d1f5305 100644 (file)
@@ -34,6 +34,7 @@ using System.Runtime.CompilerServices;
 using System.Globalization;
 using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
+using System.Text;
 
 
 namespace System.Reflection.Emit
@@ -45,22 +46,18 @@ namespace System.Reflection.Emit
 
        internal abstract class DerivedType : Type
        {
+               internal Type elementType;
+
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal static extern void create_unmanaged_type (Type type);
-       
-       }
-
-       internal class ArrayType : DerivedType
-       {
-               Type elementType;
-               int rank;
 
-               internal ArrayType (Type elementType, int rank)
+               internal DerivedType (Type elementType)
                {
                        this.elementType = elementType;
-                       this.rank = rank;
                }
 
+               internal abstract String FormatName (string elementName);
+
                public override Type GetInterface (string name, bool ignoreCase)
                {
                        throw new NotSupportedException ();
@@ -157,7 +154,7 @@ namespace System.Reflection.Emit
 
                protected override bool IsArrayImpl ()
                {
-                       return true;
+                       return false;
                }
 
                protected override bool IsByRefImpl ()
@@ -204,11 +201,6 @@ namespace System.Reflection.Emit
                        return false;
                }
 
-               public override int GetArrayRank ()
-               {
-                       return rank;
-               }
-
 #if NET_2_0
                //FIXME this should be handled by System.Type
                public override Type MakeGenericType (params Type[] typeArguments)
@@ -257,17 +249,16 @@ namespace System.Reflection.Emit
                        get { return FullName + ", " + elementType.Assembly.FullName; }
                }
 
-               public override Type BaseType {
-                       get { return typeof (System.Array); }
-               }
 
                public override string FullName {
                        get {
-                               //FIXME use a StringBuilder
-                               String commas = "";
-                               for (int i = 1; i < rank; ++i)
-                                       commas += ",";
-                               return String.Format("{0}[{1}]", elementType.FullName, commas);
+                               return FormatName (elementType.FullName);
+                       }
+               }
+
+               public override string Name {
+                       get {
+                               return FormatName (elementType.Name);
                        }
                }
 
@@ -306,15 +297,39 @@ namespace System.Reflection.Emit
                {
                        throw new NotSupportedException ();
                }
+       }
 
-               public override string Name {
-                       get {
-                               //FIXME use a StringBuilder
-                               String commas = "";
-                               for (int i = 1; i < rank; ++i)
-                                       commas += ",";
-                               return String.Format("{0}[{1}]", elementType.Name, commas);
-                       }
+       internal class ArrayType : DerivedType
+       {
+               int rank;
+
+               internal ArrayType (Type elementType, int rank) : base (elementType)
+               {
+                       this.rank = rank;
+               }
+
+               protected override bool IsArrayImpl ()
+               {
+                       return true;
+               }
+
+               public override int GetArrayRank ()
+               {
+                       return rank;
+               }
+
+               public override Type BaseType {
+                       get { return typeof (System.Array); }
+               }
+
+               internal override String FormatName (string elementName)
+               {
+                       StringBuilder sb = new StringBuilder (elementName);
+                       sb.Append ("[");
+                       for (int i = 1; i < rank; ++i)
+                               sb.Append (",");
+                       sb.Append ("]");
+                       return sb.ToString ();
                }
        }
 }