From c229b4930aae53fd31bdcc0b75275bc54f5257ad Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 24 Oct 2007 08:30:51 +0000 Subject: [PATCH] 2007-10-24 Atsushi Enomoto * Type.cs : implemented ReflectionOnlyGetType(). * TypeTest.cs : tests for ReflectionOnlyGetType(). svn path=/trunk/mcs/; revision=88053 --- mcs/class/corlib/System/ChangeLog | 4 ++++ mcs/class/corlib/System/Type.cs | 17 +++++++++++++-- mcs/class/corlib/Test/System/ChangeLog | 4 ++++ mcs/class/corlib/Test/System/TypeTest.cs | 27 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/mcs/class/corlib/System/ChangeLog b/mcs/class/corlib/System/ChangeLog index 2741821941a..e3523975e5e 100644 --- a/mcs/class/corlib/System/ChangeLog +++ b/mcs/class/corlib/System/ChangeLog @@ -1,3 +1,7 @@ +2007-10-24 Atsushi Enomoto + + * Type.cs : implemented ReflectionOnlyGetType(). + 2007-10-19 Zoltan Varga * AppDomain.cs: Add NET 3.5 DefineDynamicAssembly () overloads. diff --git a/mcs/class/corlib/System/Type.cs b/mcs/class/corlib/System/Type.cs index e8c5d5650a0..ba47762b486 100644 --- a/mcs/class/corlib/System/Type.cs +++ b/mcs/class/corlib/System/Type.cs @@ -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)] diff --git a/mcs/class/corlib/Test/System/ChangeLog b/mcs/class/corlib/Test/System/ChangeLog index d365570918d..44193b1e804 100644 --- a/mcs/class/corlib/Test/System/ChangeLog +++ b/mcs/class/corlib/Test/System/ChangeLog @@ -1,3 +1,7 @@ +2007-10-24 Atsushi Enomoto + + * TypeTest.cs : tests for ReflectionOnlyGetType(). + 2007-10-15 Gert Driesen * EnvironmentTest.cs: Added test for bug #333740. Made names of some diff --git a/mcs/class/corlib/Test/System/TypeTest.cs b/mcs/class/corlib/Test/System/TypeTest.cs index f65bf344022..b4e47b2c662 100644 --- a/mcs/class/corlib/Test/System/TypeTest.cs +++ b/mcs/class/corlib/Test/System/TypeTest.cs @@ -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 -- 2.25.1