From 9d1c35f0f72f588f6b362fceb927d4e95146597b Mon Sep 17 00:00:00 2001 From: sgarg Date: Thu, 23 Feb 2017 16:13:31 -0800 Subject: [PATCH 1/2] Assembly.GetType fixed (#1035) --- .../Classes/System.Reflection.Assembly.js | 6 +++--- .../GetTypeFromAssembly_Issue1035.cs | 17 +++++++++++++++++ Tests/SimpleTests.csproj | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Tests/SimpleTestCases/GetTypeFromAssembly_Issue1035.cs diff --git a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js index b03d35d05..ef20aaf62 100644 --- a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js +++ b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js @@ -54,14 +54,14 @@ $.Method({ Static: false, Public: true }, "GetType", (new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [$.String], [])), function GetType(name) { - return JSIL.GetTypeFromAssembly(this, name, null, false); + return JSIL.ReflectionGetTypeInternal(this, name, false, false); } ); $.Method({ Static: false, Public: true }, "GetType", (new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [$.String, $.Boolean], [])), function GetType(name, throwOnError) { - return JSIL.GetTypeFromAssembly(this, name, null, throwOnError); + return JSIL.ReflectionGetTypeInternal(this, name, throwOnError, false); } ); @@ -81,7 +81,7 @@ if (ignoreCase) throw new Error("ignoreCase not implemented"); - return JSIL.GetTypeFromAssembly(this, name, null, throwOnError); + return JSIL.ReflectionGetTypeInternal(this, name, throwOnError, ignoreCase); } ); diff --git a/Tests/SimpleTestCases/GetTypeFromAssembly_Issue1035.cs b/Tests/SimpleTestCases/GetTypeFromAssembly_Issue1035.cs new file mode 100644 index 000000000..8570e88cd --- /dev/null +++ b/Tests/SimpleTestCases/GetTypeFromAssembly_Issue1035.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +public static class Program +{ + public static void Main(string[] args) + { + var typeInt32 = typeof(object).Assembly.GetType("System.Int32"); + var typeDictionary = + typeof (object).Assembly.GetType( + "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[System.Object, mscorlib]]"); + Console.WriteLine( + "{0} {1}", typeInt32.Name, typeDictionary.Name + ); + + } +} \ No newline at end of file diff --git a/Tests/SimpleTests.csproj b/Tests/SimpleTests.csproj index 6c9957201..fe2112c10 100644 --- a/Tests/SimpleTests.csproj +++ b/Tests/SimpleTests.csproj @@ -143,6 +143,7 @@ + From 0cfbf85153730c7e1bec08b949d8287363162245 Mon Sep 17 00:00:00 2001 From: sgarg Date: Thu, 23 Feb 2017 18:03:48 -0800 Subject: [PATCH 2/2] Fixed failed test. --- .../Core/Reflection/Classes/System.Reflection.Assembly.js | 6 +++--- .../Reflection/Helpers/JSIL.ReflectionGetTypeInternal.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js index ef20aaf62..3436e57c7 100644 --- a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js +++ b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js @@ -54,14 +54,14 @@ $.Method({ Static: false, Public: true }, "GetType", (new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [$.String], [])), function GetType(name) { - return JSIL.ReflectionGetTypeInternal(this, name, false, false); + return JSIL.ReflectionGetTypeInternal(this, name, false, false, true); } ); $.Method({ Static: false, Public: true }, "GetType", (new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [$.String, $.Boolean], [])), function GetType(name, throwOnError) { - return JSIL.ReflectionGetTypeInternal(this, name, throwOnError, false); + return JSIL.ReflectionGetTypeInternal(this, name, throwOnError, false, true); } ); @@ -81,7 +81,7 @@ if (ignoreCase) throw new Error("ignoreCase not implemented"); - return JSIL.ReflectionGetTypeInternal(this, name, throwOnError, ignoreCase); + return JSIL.ReflectionGetTypeInternal(this, name, throwOnError, ignoreCase, true); } ); diff --git a/JSIL.Libraries/Includes/Core/Reflection/Helpers/JSIL.ReflectionGetTypeInternal.js b/JSIL.Libraries/Includes/Core/Reflection/Helpers/JSIL.ReflectionGetTypeInternal.js index d93db72ba..be349762b 100644 --- a/JSIL.Libraries/Includes/Core/Reflection/Helpers/JSIL.ReflectionGetTypeInternal.js +++ b/JSIL.Libraries/Includes/Core/Reflection/Helpers/JSIL.ReflectionGetTypeInternal.js @@ -1,10 +1,10 @@ -JSIL.ReflectionGetTypeInternal = function (thisAssembly, name, throwOnFail, ignoreCase) { +JSIL.ReflectionGetTypeInternal = function (thisAssembly, name, throwOnFail, ignoreCase, onlySpecificAssembly) { var parsed = JSIL.ParseTypeName(name); var result = JSIL.GetTypeInternal(parsed, thisAssembly, false); // HACK: Emulate fallback to global namespace search. - if (!result) { + if (!result && !onlySpecificAssembly) { result = JSIL.GetTypeInternal(parsed, JSIL.GlobalNamespace, false); }