Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

TypeInfo Api #1043

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
}
);
}
);
);

JSIL.MakeStaticClass("System.Reflection.IntrospectionExtensions", true, [], function ($) {
});
14 changes: 14 additions & 0 deletions JSIL.Libraries/Includes/Core/Reflection/Classes/System.Type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion JSIL.Libraries/Sources/JSIL.Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
14 changes: 13 additions & 1 deletion Proxies/BCL/JSIL.Core.Reflection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
using JSIL.Meta;
using JSIL.Proxy;

Expand All @@ -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();
}
}
}
8 changes: 4 additions & 4 deletions Tests/MetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [] { ".*" }
);

Expand Down Expand Up @@ -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("));
Expand Down Expand Up @@ -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[] { ".*" }
);

Expand All @@ -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[] { ".*" }
);

Expand Down
22 changes: 22 additions & 0 deletions Tests/SimpleTestCases/TypeInfoApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

public static class Program {
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<int>).GetTypeInfo().GenericTypeArguments[0] == typeof(int) ? "true" : "false");
}
}
1 change: 1 addition & 0 deletions Tests/SimpleTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<None Include="SimpleTestCasesForTranslatedBcl\Issue1008_MethodReturnType.cs" />
<None Include="SimpleTestCases\GetTypeFromAssembly_Issue1035.cs" />
<None Include="SimpleTestCases\AsyncAwaitCancel.cs" />
<None Include="SimpleTestCases\TypeInfoApi.cs" />
<Compile Include="SimpleTests.cs" />
<None Include="SimpleTestCases\BaseAutoProperties.cs" />
<None Include="SimpleTestCases\OverloadedVirtualMethods.cs" />
Expand Down