From fd373fe31c2b4c370e2eb8cabd6785d95d73f9ac Mon Sep 17 00:00:00 2001 From: "michael.daveynis" Date: Fri, 10 Mar 2017 19:32:23 -0800 Subject: [PATCH 1/5] Added IEnumerable TypeInfo.DeclaredConstructors { get; } Added Type[] Type.GenericTypeArguments { get; } Fixed System.Reflection.IntrospectionExtensions for ignored BCL. --- .../System.Reflection.IntrospectionExtensions.js | 5 ++++- .../Core/Reflection/Classes/System.Type.js | 14 ++++++++++++++ Tests/SimpleTestCases/TypeInfoApi.cs | 11 +++++++++++ Tests/SimpleTests.csproj | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Tests/SimpleTestCases/TypeInfoApi.cs diff --git a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.IntrospectionExtensions.js b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.IntrospectionExtensions.js index 2e10dd37b..6aab7db7b 100644 --- a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.IntrospectionExtensions.js +++ b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.IntrospectionExtensions.js @@ -7,4 +7,7 @@ } ); } -); \ No newline at end of file +); + +JSIL.MakeStaticClass("System.Reflection.IntrospectionExtensions", true, [], function ($) { +}); \ No newline at end of file diff --git a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Type.js b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Type.js index 62f5d63eb..732f9bec2 100644 --- a/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Type.js +++ b/JSIL.Libraries/Includes/Core/Reflection/Classes/System.Type.js @@ -71,6 +71,13 @@ } ); + $.Method({ Static: false, Public: true }, "get_GenericTypeArguments", + (new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", [$.Type]), [], [])), + function GetGenericArguments() { + return this.GetGenericArguments(); + } + ); + $.Method({ Static: false, Public: true }, "MakeGenericType", (new JSIL.MethodSignature($.Type, [$jsilcore.TypeRef("System.Array", [$.Type])], [])), function (typeArguments) { @@ -403,6 +410,13 @@ } ); + $.Method({ Static: false, Public: true }, "get_DeclaredConstructors", + new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", [$jsilcore.TypeRef("System.Reflection.ConstructorInfo")]), []), + function () { + return this.GetConstructors(); + } + ); + $.Method({ Public: true, Static: false }, "GetFields", new JSIL.MethodSignature(fieldArray, []), function () { diff --git a/Tests/SimpleTestCases/TypeInfoApi.cs b/Tests/SimpleTestCases/TypeInfoApi.cs new file mode 100644 index 000000000..16d713351 --- /dev/null +++ b/Tests/SimpleTestCases/TypeInfoApi.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +public static class Program { + public static void Main (string[] args) { + Console.WriteLine(IntrospectionExtensions.GetTypeInfo(typeof(Exception)).DeclaredConstructors.First(obj => obj.GetParameters().Length == 2)); + Console.WriteLine(typeof(List).GetTypeInfo().GenericTypeArguments[0] == typeof(int) ? "true" : "false"); + } +} \ No newline at end of file diff --git a/Tests/SimpleTests.csproj b/Tests/SimpleTests.csproj index dc6faeada..917e886c7 100644 --- a/Tests/SimpleTests.csproj +++ b/Tests/SimpleTests.csproj @@ -147,6 +147,7 @@ + From 57992e9fe1f90ed17006fffeac658bb2f1917609 Mon Sep 17 00:00:00 2001 From: "michael.daveynis" Date: Fri, 10 Mar 2017 19:32:34 -0800 Subject: [PATCH 2/5] Updated toString of Void signature --- JSIL.Libraries/Sources/JSIL.Core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JSIL.Libraries/Sources/JSIL.Core.js b/JSIL.Libraries/Sources/JSIL.Core.js index 773d5ff9c..f3894df76 100644 --- a/JSIL.Libraries/Sources/JSIL.Core.js +++ b/JSIL.Libraries/Sources/JSIL.Core.js @@ -7539,7 +7539,7 @@ JSIL.MethodSignature.prototype.toString = function (name, includeReturnType) { } else if (this.returnType !== null) { signature = JSIL.TypeReferenceToName(this.returnType) + " "; } else { - signature = "void "; + signature = "Void "; } if (typeof (name) === "string") { From bdbd230ce1cb346f2789159afa31db8ecd165c94 Mon Sep 17 00:00:00 2001 From: "michael.daveynis" Date: Tue, 14 Mar 2017 19:41:18 -0700 Subject: [PATCH 3/5] Update test to avoid System.Type.ToString() differences. --- Tests/SimpleTestCases/TypeInfoApi.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Tests/SimpleTestCases/TypeInfoApi.cs b/Tests/SimpleTestCases/TypeInfoApi.cs index 16d713351..fc47b8022 100644 --- a/Tests/SimpleTestCases/TypeInfoApi.cs +++ b/Tests/SimpleTestCases/TypeInfoApi.cs @@ -4,8 +4,19 @@ using System.Reflection; public static class Program { - public static void Main (string[] args) { - Console.WriteLine(IntrospectionExtensions.GetTypeInfo(typeof(Exception)).DeclaredConstructors.First(obj => obj.GetParameters().Length == 2)); + public static void Main (string[] args) + { + var assertion = IntrospectionExtensions.GetTypeInfo(typeof(Exception)).DeclaredConstructors + .Any(obj => obj.GetParameters().Length == 2 + && obj.GetParameters()[0].ParameterType == typeof(string) + && obj.GetParameters()[1].ParameterType == typeof(Exception)); + if (!assertion) + { + throw new Exception("Invalid result for DeclaredConstructors"); + } + + Console.WriteLine(assertion ? "true" : "false"); + Console.WriteLine(typeof(List).GetTypeInfo().GenericTypeArguments[0] == typeof(int) ? "true" : "false"); } } \ No newline at end of file From 74a852d91713097e10b8a202bcd77fbfef01dd2b Mon Sep 17 00:00:00 2001 From: "michael.daveynis" Date: Tue, 14 Mar 2017 20:22:09 -0700 Subject: [PATCH 4/5] Update tests signatures: void -> Void --- Tests/MetadataTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/MetadataTests.cs b/Tests/MetadataTests.cs index 62c2cafdc..dc65e70d5 100644 --- a/Tests/MetadataTests.cs +++ b/Tests/MetadataTests.cs @@ -187,7 +187,7 @@ public void StubbedAssembliesDoNotGenerateMethodBodies () { var generatedJs = GenericIgnoreTest( @"SpecialTestCases\StubbedMethodBodies.cs", "", - "The external method 'void Main(System.String[])' of type 'Program'", + "The external method 'Void Main(System.String[])' of type 'Program'", new [] { ".*" } ); @@ -330,7 +330,7 @@ public void RenameStaticClass () { public void ExternalMethod () { var generatedJs = GenericIgnoreTest( @"SpecialTestCases\ExternalMethod.cs", - "Method", "external method 'void Method()' of type 'Program' has not" + "Method", "external method 'Void Method()' of type 'Program' has not" ); Assert.IsTrue(generatedJs.Contains("$thisType.Method(")); @@ -541,7 +541,7 @@ public void CanForceTranslationOfTypeInStubbedAssembly () { var generatedJs = GenericIgnoreTest( @"SpecialTestCases\TranslateTypeInStubbedAssembly.cs", "", - "method 'void Main(System.String[])' of type 'Program'", + "method 'Void Main(System.String[])' of type 'Program'", new[] { ".*" } ); @@ -563,7 +563,7 @@ public void CanForceTranslationOfMethodInStubbedAssembly () { var generatedJs = GenericIgnoreTest( @"SpecialTestCases\TranslateMethodInStubbedAssembly.cs", expectedOutput, - "method 'void Main(System.String[])' of type 'Program'", + "method 'Void Main(System.String[])' of type 'Program'", new[] { ".*" } ); From 80886e5219eaa5eff6b13e87b623bf946dcc7b41 Mon Sep 17 00:00:00 2001 From: "michael.daveynis" Date: Fri, 17 Mar 2017 17:10:38 -0700 Subject: [PATCH 5/5] BCL Proxy stub for System_Reflection_IntrospectionExtensions.GetTypeInfo --- Proxies/BCL/JSIL.Core.Reflection.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Proxies/BCL/JSIL.Core.Reflection.cs b/Proxies/BCL/JSIL.Core.Reflection.cs index a975306bf..238863081 100644 --- a/Proxies/BCL/JSIL.Core.Reflection.cs +++ b/Proxies/BCL/JSIL.Core.Reflection.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; using JSIL.Meta; using JSIL.Proxy; @@ -15,4 +16,15 @@ public class System_Reflection_ParameterInfo public class System_Reflection_EventInfo { } + + [JSProxy("System.Reflection.IntrospectionExtensions", JSProxyMemberPolicy.ReplaceNone, JSProxyAttributePolicy.ReplaceDeclared, JSProxyInterfacePolicy.ReplaceNone, false)] + [JSStubOnly] + public class System_Reflection_IntrospectionExtensions + { + [JSExternal] + public static AnyType /* System.Reflection.TypeInfo */ GetTypeInfo(Type type) + { + throw new NotImplementedException(); + } + } }