public
Created

JSIL Code Sample: Closures

  • Download Gist
DisplayClassFieldNames.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14
using System;
 
public static class Program {
public static void Main (string[] args) {
int x = 1;
string y = "y";
 
Func<string> a = () => {
return String.Format("x={0}, y={1}", x, y);
};
 
Console.WriteLine("a()={0}", a());
}
}
DisplayClassFieldNames.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
JSIL.MakeStaticClass("Program", true, [], function ($) {
 
$.Method({Static:true , Public:true }, "Main",
$sig.get(1, null, [$jsilcore.TypeRef("System.Array", [$.String])], []),
function Main (args) {
var $l$gc__DisplayClass = new $asm00.Program_$l$gc__DisplayClass1();
$l$gc__DisplayClass.x = 1;
$l$gc__DisplayClass.y = "y";
var a = function () {
return $asm01.System.String.Format("x={0}, y={1}", this.x, this.y);
}.bind($l$gc__DisplayClass);
$asm01.System.Console.WriteLine("a()={0}", a());
}
);
 
});
 
JSIL.MakeClass($asm01.TypeRef("System.Object"), "Program/<>c__DisplayClass1", false, [], function ($) {
 
$.Method({Static:false, Public:true }, ".ctor",
$sig.get(2, null, [], []),
function _ctor () {
}
);
 
$.Field({Static:false, Public:true }, "x", $.Int32, function ($) {
return 0;
});
 
$.Field({Static:false, Public:true }, "y", $.String, function ($) {
return null;
});
 
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.