Created
June 7, 2011 08:25
-
-
Save kg/1011893 to your computer and use it in GitHub Desktop.
JSIL Code Sample: Closures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment