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

Commit eebc933

Browse files
committed
Merge pull request #874 from iskiselev/Misc_Reflection
Misc reflection
2 parents 1ed796b + b9bf55a commit eebc933

40 files changed

+747
-108
lines changed

JSIL.Libraries/Includes/Bootstrap/Core/Classes/System.Array.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,23 @@ JSIL.ImplementExternals("System.Array", function ($) {
172172
reverseImpl(array, index, length);
173173
}
174174
);
175-
});
175+
176+
$.Method({ Static: true, Public: true }, "Empty",
177+
new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", ["!!0"]), [], ["T"]),
178+
function Empty(T) {
179+
return $jsilcore.System.Array_EmptyArray$b1.Of(T).Value;
180+
}
181+
);
182+
});
183+
184+
185+
JSIL.MakeStaticClass("System.Array+EmptyArray`1", false, ["T"], function($) {
186+
$.Field({ Static: true, Public: true, ReadOnly: true }, "Value", $jsilcore.TypeRef("System.Array", [$.GenericParameter("T")]));
187+
188+
$.Method({ Static: true, Public: false }, ".cctor",
189+
JSIL.MethodSignature.Void,
190+
function EmptyArray$b1__cctor() {
191+
this.Value = JSIL.Array.New(this.T, 0);
192+
}
193+
);
194+
});

JSIL.Libraries/Includes/Bootstrap/Core/Classes/System.Enum.js

+7
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,12 @@
141141
return result;
142142
}
143143
);
144+
145+
$.Method({ Static: true, Public: true }, "GetUnderlyingType",
146+
new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [$jsilcore.TypeRef("System.Type")], []),
147+
function (enm) {
148+
return enm.__StorageType__;
149+
}
150+
);
144151
}
145152
);

JSIL.Libraries/Includes/Bootstrap/Core/Classes/System.Threading.Thread.js

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
return 0;
2525
}
2626
);
27+
28+
$.Method({ Static: true, Public: true }, "MemoryBarrier",
29+
JSIL.MethodSignature.Void,
30+
function thread_MemoryBarrier() {
31+
}
32+
);
2733
}
2834
);
2935

JSIL.Libraries/Includes/Bootstrap/Text/Classes/System.Char.js

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ JSIL.ImplementExternals("System.Char", function ($) {
2828
}
2929
);
3030

31+
$.Method({ Static: true, Public: true }, "IsNumber",
32+
new JSIL.MethodSignature($.Boolean, [$.Char], []),
33+
function IsNumeric(c) {
34+
// FIXME: Unicode
35+
var charCode = c.charCodeAt(0);
36+
return (charCode >= 48) && (charCode <= 57);
37+
}
38+
);
39+
3140
$.Method({ Static: true, Public: true }, "IsLetterOrDigit",
3241
new JSIL.MethodSignature($.Boolean, [$.Char], []),
3342
function IsLetterOrDigit(c) {

JSIL.Libraries/Includes/Bootstrap/Text/Classes/System.String.js

+8
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,17 @@ JSIL.ImplementExternals(
271271
}
272272
}
273273
);
274+
275+
$.Method({ Static: false, Public: true }, "get_Length",
276+
new JSIL.MethodSignature($.Int32, [], []),
277+
function() {
278+
return this.length;
279+
}
280+
);
274281
}
275282
);
276283

277284
JSIL.MakeClass("System.Object", "System.String", true, [], function ($) {
278285
$.Field({ Static: true, Public: true }, "Empty", $.String, "");
286+
$.Property({ Public: true, Static: false }, "Length");
279287
});

JSIL.Libraries/Includes/Bootstrap/Text/Helpers/JSIL.StringFromCharArray.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ JSIL.StringFromCharArray = function (chars, startIndex, length) {
55
length = chars.length;
66

77
if (arguments.length > 1) {
8-
var arr = chars.slice(startIndex, length);
8+
var arr = chars.slice(startIndex, startIndex + length);
99
return arr.join("");
1010
} else {
1111
return chars.join("");
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
JSIL.ImplementExternals("System.Attribute", function ($) {
2-
$.Method({ Static: true, Public: true }, "GetCustomAttribute",
3-
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Attribute"), [$jsilcore.TypeRef("System.Reflection.Assembly"), $jsilcore.TypeRef("System.Type")], [])),
4-
function GetCustomAttribute(assembly, attributeType) {
5-
// FIXME: Not implemented
6-
return null;
7-
}
8-
);
92
});

JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.Assembly.js

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@
6565
}
6666
);
6767

68+
$.Method({ Static: true, Public: true }, "Load",
69+
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.Assembly"), [$.String], [])),
70+
function Load(assemblyName) {
71+
return JSIL.GetAssembly(assemblyName).__Assembly__;
72+
}
73+
);
74+
6875
$.Method({ Static: false, Public: true }, "GetType",
6976
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [
7077
$.String, $.Boolean,

JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.MethodBase.js

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
return this._data.signature.toString(this.Name);
2727
}
2828
);
29+
30+
$.Method({ Public: true, Static: false }, "get_IsConstructor",
31+
new JSIL.MethodSignature($.Boolean, []),
32+
function get_IsConstructor() {
33+
return $jsilcore.System.Reflection.ConstructorInfo.$Is(this) && !this.get_IsStatic();
34+
}
35+
);
2936
}
3037
);
3138

JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.MethodInfo.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
if (result)
9595
return result;
9696

97-
var parsedTypeName = JSIL.ParseTypeName("System.Reflection.MethodInfo");
97+
var parsedTypeName = JSIL.ParseTypeName("System.Reflection.RuntimeMethodInfo");
9898
var infoType = JSIL.GetTypeInternal(parsedTypeName, $jsilcore, true);
9999
var info = JSIL.CreateInstanceOfType(infoType, null);
100100
info._typeObject = this._typeObject;
@@ -123,6 +123,13 @@
123123
}
124124
);
125125

126+
$.Method({ Public: true, Static: false }, "get_IsVirtual",
127+
new JSIL.MethodSignature($.Type, []),
128+
function get_IsGenericMethod() {
129+
return this._descriptor.Virtual;
130+
}
131+
);
132+
126133
$.Method({ Public: true, Static: false }, "get_IsGenericMethodDefinition",
127134
new JSIL.MethodSignature($.Type, []),
128135
function get_IsGenericMethodDefinition() {
@@ -136,6 +143,21 @@
136143
return this.DeclaringType.get_ContainsGenericParameters() || (this._data.signature.genericArgumentNames.length !== 0 && this._data.signature.genericArgumentValues === undefined);
137144
}
138145
);
146+
147+
$.Method({ Static: false, Public: true }, "GetBaseDefinition",
148+
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.MethodInfo"), [], [])),
149+
function getBaseDefinition() {
150+
var previous;
151+
var current = this;
152+
153+
do {
154+
previous = current;
155+
current = current.GetParentDefinition();
156+
} while (current !== null)
157+
158+
return previous;
159+
}
160+
);
139161
});
140162

141163
JSIL.MakeClass("System.Reflection.MethodBase", "System.Reflection.MethodInfo", true, [], function ($) {

JSIL.Libraries/Includes/Core/Reflection/Classes/System.Reflection.ParameterInfo.js

-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
JSIL.ImplementExternals("System.Reflection.ParameterInfo", function ($interfaceBuilder) {
22
var $ = $interfaceBuilder;
33

4-
$.RawMethod(false, "$fromArgumentTypeAndPosition", function (argumentType, position) {
5-
this.argumentType = argumentType;
6-
this.position = position;
7-
this._name = null;
8-
this.__Attributes__ = [];
9-
});
10-
11-
$.RawMethod(false, "$populateWithParameterInfo", function (parameterInfo) {
12-
this._name = parameterInfo.name || null;
13-
14-
if (parameterInfo.attributes) {
15-
var mb = new JSIL.MemberBuilder(null);
16-
parameterInfo.attributes(mb);
17-
this.__Attributes__ = mb.attributes;
18-
}
19-
});
20-
214
$.Method({ Static: false, Public: true }, "get_Attributes",
225
new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.ParameterAttributes"), [], []),
236
function get_Attributes() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JSIL.MakeClass("System.Reflection.ConstructorInfo", "System.Reflection.RuntimeConstructorInfo", false, [], function ($) {
2+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JSIL.MakeClass("System.Reflection.EventInfo", "System.Reflection.RuntimeEventInfo", false, [], function ($) {
2+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JSIL.MakeClass("System.Reflection.FieldInfo", "System.Reflection.RuntimeFieldInfo", false, [], function ($) {
2+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
JSIL.MakeClass("System.Reflection.MethodInfo", "System.Reflection.RuntimeMethodInfo", false, [], function ($) {
2+
$.Method({ Static: false, Public: false }, "GetParentDefinition",
3+
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.RuntimeMethodInfo"), [], [])),
4+
function get_ReturnType() {
5+
if (!this._descriptor.Virtual || this._descriptor.Static) {
6+
return null;
7+
}
8+
9+
var currentType = this.get_DeclaringType();
10+
while (true) {
11+
currentType = currentType.__BaseType__;
12+
if (!(currentType && currentType.GetType)) {
13+
return null;
14+
}
15+
var foundMethod = JSIL.GetMethodInfo(currentType.__PublicInterface__, this.get_Name(), this._data.signature, false, null);
16+
if (foundMethod != null) {
17+
return foundMethod;
18+
}
19+
}
20+
}
21+
);
22+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
JSIL.MakeClass("System.Reflection.ParameterInfo", "System.Reflection.RuntimeParameterInfo", false, [], function ($) {
2+
$.RawMethod(false, "$fromArgumentTypeAndPosition", function (argumentType, position) {
3+
this.argumentType = argumentType;
4+
this.position = position;
5+
this._name = null;
6+
this.__Attributes__ = [];
7+
});
8+
9+
$.RawMethod(false, "$populateWithParameterInfo", function (parameterInfo) {
10+
this._name = parameterInfo.name || null;
11+
12+
if (parameterInfo.attributes) {
13+
var mb = new JSIL.MemberBuilder(null);
14+
parameterInfo.attributes(mb);
15+
this.__Attributes__ = mb.attributes;
16+
}
17+
});
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
JSIL.MakeClass("System.Reflection.PropertyInfo", "System.Reflection.RuntimePropertyInfo", false, [], function ($) {
2+
});
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
JSIL.MakeClass("System.Reflection.TypeInfo", "System.RuntimeType", false, [], function ($) {
22
$jsilcore.RuntimeTypeInitialized = true;
3+
4+
$.Method({ Public: true, Static: true }, "op_Equality",
5+
new JSIL.MethodSignature($.Boolean, [$.Type, $.Type]),
6+
function(lhs, rhs) {
7+
if (lhs === rhs)
8+
return true;
9+
10+
return String(lhs) == String(rhs);
11+
}
12+
);
313
});

0 commit comments

Comments
 (0)