2007-10-24 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 24 Oct 2007 08:30:51 +0000 (08:30 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 24 Oct 2007 08:30:51 +0000 (08:30 -0000)
* Type.cs : implemented ReflectionOnlyGetType().

* TypeTest.cs : tests for ReflectionOnlyGetType().

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

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/Type.cs
mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/TypeTest.cs

index 2741821941a4e20f9c621f64e56af15b56b9d76f..e3523975e5ee019091d9b7a7b5984bdd0a53e9f6 100644 (file)
@@ -1,3 +1,7 @@
+2007-10-24  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Type.cs : implemented ReflectionOnlyGetType().
+
 2007-10-19  Zoltan Varga  <vargaz@gmail.com>
 
        * AppDomain.cs: Add NET 3.5 DefineDynamicAssembly () overloads.
index e8c5d5650a0c356e4f61204eb466fb76567d5b1e..ba47762b4864665ab80810c356449486beb99767 100644 (file)
@@ -1247,12 +1247,25 @@ namespace System {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern virtual Type MakePointerType ();
 
-               [MonoTODO("Not implemented")]
                public static Type ReflectionOnlyGetType (string typeName, 
                                                          bool throwIfNotFound, 
                                                          bool ignoreCase)
                {
-                       throw new NotImplementedException ();
+                       if (typeName == null)
+                               throw new ArgumentNullException ("typeName");
+                       int idx = typeName.IndexOf (',');
+                       if (idx < 0 || idx == 0 || idx == typeName.Length - 1)
+                               throw new ArgumentException ("Assembly qualifed type name is required", "typeName");
+                       string an = typeName.Substring (idx + 1);
+                       Assembly a;
+                       try {
+                               a = Assembly.ReflectionOnlyLoad (an);
+                       } catch (Exception ex) {
+                               if (throwIfNotFound)
+                                       throw;
+                               return null;
+                       }
+                       return a.GetType (typeName.Substring (0, idx), throwIfNotFound, ignoreCase);
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
index d365570918d1bb9466f4473de50c72678d67018c..44193b1e804773a09d78c19f4d444a4e099c4776 100644 (file)
@@ -1,3 +1,7 @@
+2007-10-24  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * TypeTest.cs : tests for ReflectionOnlyGetType().
+
 2007-10-15  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * EnvironmentTest.cs: Added test for bug #333740. Made names of some
index f65bf3440220ddf4371d68c000bf3e36f6e62287..b4e47b2c6620acb0b931c259a92109ac299b4059 100644 (file)
@@ -1183,6 +1183,33 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.IsNotNull (members, "#1");
                        Assert.AreEqual (4, members.Length, "#2");
                }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ReflectionOnlyGetTypeNullTypeName ()
+               {
+                       Type.ReflectionOnlyGetType (null, false, false);
+               }
+
+               [Test]
+               public void ReflectionOnlyGetTypeDoNotThrow ()
+               {
+                       Assert.IsNull (Type.ReflectionOnlyGetType ("a, nonexistent.dll", false, false));
+               }
+
+               [Test]
+               [ExpectedException (typeof (FileNotFoundException))]
+               public void ReflectionOnlyGetTypeThrow ()
+               {
+                       Type.ReflectionOnlyGetType ("a, nonexistent.dll", true, false);
+               }
+
+               [Test]
+               public void ReflectionOnlyGetType ()
+               {
+                       Type t = Type.ReflectionOnlyGetType (typeof (int).AssemblyQualifiedName.ToString (), true, true);
+                       Assert.AreEqual ("System.Int32", t.FullName);
+               }
 #endif
 
                public class NemerleAttribute : Attribute