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

Commit

Permalink
Merge pull request #874 from iskiselev/Misc_Reflection
Browse files Browse the repository at this point in the history
Misc reflection
  • Loading branch information
kg committed Oct 17, 2015
2 parents 1ed796b + b9bf55a commit eebc933
Show file tree
Hide file tree
Showing 40 changed files with 747 additions and 108 deletions.
21 changes: 20 additions & 1 deletion JSIL.Libraries/Includes/Bootstrap/Core/Classes/System.Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,23 @@ JSIL.ImplementExternals("System.Array", function ($) {
reverseImpl(array, index, length);
}
);
});

$.Method({ Static: true, Public: true }, "Empty",
new JSIL.MethodSignature($jsilcore.TypeRef("System.Array", ["!!0"]), [], ["T"]),
function Empty(T) {
return $jsilcore.System.Array_EmptyArray$b1.Of(T).Value;
}
);
});


JSIL.MakeStaticClass("System.Array+EmptyArray`1", false, ["T"], function($) {
$.Field({ Static: true, Public: true, ReadOnly: true }, "Value", $jsilcore.TypeRef("System.Array", [$.GenericParameter("T")]));

$.Method({ Static: true, Public: false }, ".cctor",
JSIL.MethodSignature.Void,
function EmptyArray$b1__cctor() {
this.Value = JSIL.Array.New(this.T, 0);
}
);
});
7 changes: 7 additions & 0 deletions JSIL.Libraries/Includes/Bootstrap/Core/Classes/System.Enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,12 @@
return result;
}
);

$.Method({ Static: true, Public: true }, "GetUnderlyingType",
new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [$jsilcore.TypeRef("System.Type")], []),
function (enm) {
return enm.__StorageType__;
}
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
return 0;
}
);

$.Method({ Static: true, Public: true }, "MemoryBarrier",
JSIL.MethodSignature.Void,
function thread_MemoryBarrier() {
}
);
}
);

Expand Down
9 changes: 9 additions & 0 deletions JSIL.Libraries/Includes/Bootstrap/Text/Classes/System.Char.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ JSIL.ImplementExternals("System.Char", function ($) {
}
);

$.Method({ Static: true, Public: true }, "IsNumber",
new JSIL.MethodSignature($.Boolean, [$.Char], []),
function IsNumeric(c) {
// FIXME: Unicode
var charCode = c.charCodeAt(0);
return (charCode >= 48) && (charCode <= 57);
}
);

$.Method({ Static: true, Public: true }, "IsLetterOrDigit",
new JSIL.MethodSignature($.Boolean, [$.Char], []),
function IsLetterOrDigit(c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,17 @@ JSIL.ImplementExternals(
}
}
);

$.Method({ Static: false, Public: true }, "get_Length",
new JSIL.MethodSignature($.Int32, [], []),
function() {
return this.length;
}
);
}
);

JSIL.MakeClass("System.Object", "System.String", true, [], function ($) {
$.Field({ Static: true, Public: true }, "Empty", $.String, "");
$.Property({ Public: true, Static: false }, "Length");
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ JSIL.StringFromCharArray = function (chars, startIndex, length) {
length = chars.length;

if (arguments.length > 1) {
var arr = chars.slice(startIndex, length);
var arr = chars.slice(startIndex, startIndex + length);
return arr.join("");
} else {
return chars.join("");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
JSIL.ImplementExternals("System.Attribute", function ($) {
$.Method({ Static: true, Public: true }, "GetCustomAttribute",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Attribute"), [$jsilcore.TypeRef("System.Reflection.Assembly"), $jsilcore.TypeRef("System.Type")], [])),
function GetCustomAttribute(assembly, attributeType) {
// FIXME: Not implemented
return null;
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
}
);

$.Method({ Static: true, Public: true }, "Load",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.Assembly"), [$.String], [])),
function Load(assemblyName) {
return JSIL.GetAssembly(assemblyName).__Assembly__;
}
);

$.Method({ Static: false, Public: true }, "GetType",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Type"), [
$.String, $.Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
return this._data.signature.toString(this.Name);
}
);

$.Method({ Public: true, Static: false }, "get_IsConstructor",
new JSIL.MethodSignature($.Boolean, []),
function get_IsConstructor() {
return $jsilcore.System.Reflection.ConstructorInfo.$Is(this) && !this.get_IsStatic();
}
);
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
if (result)
return result;

var parsedTypeName = JSIL.ParseTypeName("System.Reflection.MethodInfo");
var parsedTypeName = JSIL.ParseTypeName("System.Reflection.RuntimeMethodInfo");
var infoType = JSIL.GetTypeInternal(parsedTypeName, $jsilcore, true);
var info = JSIL.CreateInstanceOfType(infoType, null);
info._typeObject = this._typeObject;
Expand Down Expand Up @@ -123,6 +123,13 @@
}
);

$.Method({ Public: true, Static: false }, "get_IsVirtual",
new JSIL.MethodSignature($.Type, []),
function get_IsGenericMethod() {
return this._descriptor.Virtual;
}
);

$.Method({ Public: true, Static: false }, "get_IsGenericMethodDefinition",
new JSIL.MethodSignature($.Type, []),
function get_IsGenericMethodDefinition() {
Expand All @@ -136,6 +143,21 @@
return this.DeclaringType.get_ContainsGenericParameters() || (this._data.signature.genericArgumentNames.length !== 0 && this._data.signature.genericArgumentValues === undefined);
}
);

$.Method({ Static: false, Public: true }, "GetBaseDefinition",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.MethodInfo"), [], [])),
function getBaseDefinition() {
var previous;
var current = this;

do {
previous = current;
current = current.GetParentDefinition();
} while (current !== null)

return previous;
}
);
});

JSIL.MakeClass("System.Reflection.MethodBase", "System.Reflection.MethodInfo", true, [], function ($) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
JSIL.ImplementExternals("System.Reflection.ParameterInfo", function ($interfaceBuilder) {
var $ = $interfaceBuilder;

$.RawMethod(false, "$fromArgumentTypeAndPosition", function (argumentType, position) {
this.argumentType = argumentType;
this.position = position;
this._name = null;
this.__Attributes__ = [];
});

$.RawMethod(false, "$populateWithParameterInfo", function (parameterInfo) {
this._name = parameterInfo.name || null;

if (parameterInfo.attributes) {
var mb = new JSIL.MemberBuilder(null);
parameterInfo.attributes(mb);
this.__Attributes__ = mb.attributes;
}
});

$.Method({ Static: false, Public: true }, "get_Attributes",
new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.ParameterAttributes"), [], []),
function get_Attributes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSIL.MakeClass("System.Reflection.ConstructorInfo", "System.Reflection.RuntimeConstructorInfo", false, [], function ($) {
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSIL.MakeClass("System.Reflection.EventInfo", "System.Reflection.RuntimeEventInfo", false, [], function ($) {
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSIL.MakeClass("System.Reflection.FieldInfo", "System.Reflection.RuntimeFieldInfo", false, [], function ($) {
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
JSIL.MakeClass("System.Reflection.MethodInfo", "System.Reflection.RuntimeMethodInfo", false, [], function ($) {
$.Method({ Static: false, Public: false }, "GetParentDefinition",
(new JSIL.MethodSignature($jsilcore.TypeRef("System.Reflection.RuntimeMethodInfo"), [], [])),
function get_ReturnType() {
if (!this._descriptor.Virtual || this._descriptor.Static) {
return null;
}

var currentType = this.get_DeclaringType();
while (true) {
currentType = currentType.__BaseType__;
if (!(currentType && currentType.GetType)) {
return null;
}
var foundMethod = JSIL.GetMethodInfo(currentType.__PublicInterface__, this.get_Name(), this._data.signature, false, null);
if (foundMethod != null) {
return foundMethod;
}
}
}
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
JSIL.MakeClass("System.Reflection.ParameterInfo", "System.Reflection.RuntimeParameterInfo", false, [], function ($) {
$.RawMethod(false, "$fromArgumentTypeAndPosition", function (argumentType, position) {
this.argumentType = argumentType;
this.position = position;
this._name = null;
this.__Attributes__ = [];
});

$.RawMethod(false, "$populateWithParameterInfo", function (parameterInfo) {
this._name = parameterInfo.name || null;

if (parameterInfo.attributes) {
var mb = new JSIL.MemberBuilder(null);
parameterInfo.attributes(mb);
this.__Attributes__ = mb.attributes;
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSIL.MakeClass("System.Reflection.PropertyInfo", "System.Reflection.RuntimePropertyInfo", false, [], function ($) {
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
JSIL.MakeClass("System.Reflection.TypeInfo", "System.RuntimeType", false, [], function ($) {
$jsilcore.RuntimeTypeInitialized = true;

$.Method({ Public: true, Static: true }, "op_Equality",
new JSIL.MethodSignature($.Boolean, [$.Type, $.Type]),
function(lhs, rhs) {
if (lhs === rhs)
return true;

return String(lhs) == String(rhs);
}
);
});
Loading

0 comments on commit eebc933

Please sign in to comment.