Created
June 7, 2011 08:12
-
-
Save kg/1011876 to your computer and use it in GitHub Desktop.
JSIL Code Sample: MulticastDelegates
This file contains hidden or 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) { | |
Action<int> a = | |
(i) => Console.WriteLine("a({0})", i); | |
Action<int> b = | |
(i) => Console.WriteLine("b({0})", i); | |
Action<int> c = (Action<int>)Delegate.Combine(a, b); | |
a(1); | |
b(2); | |
c(3); | |
var d = (Action<int>)Delegate.Remove(c, a); | |
d(4); | |
} | |
public static void PrintNumber (int x) { | |
Console.WriteLine("PrintNumber({0})", x); | |
} | |
} |
This file contains hidden or 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 a = function (i) { | |
$asm01.System.Console.WriteLine("a({0})", i); | |
}; | |
var b = function (i) { | |
$asm01.System.Console.WriteLine("b({0})", i); | |
}; | |
var c = $asm01.System.Delegate.Combine(a, b); | |
a(1); | |
b(2); | |
c(3); | |
var d = $asm01.System.Delegate.Remove(c, a); | |
d(4); | |
} | |
); | |
$.Method({Static:true , Public:true }, "PrintNumber", | |
$sig.get(2, null, [$.Int32], []), | |
function PrintNumber (x) { | |
$asm01.System.Console.WriteLine("PrintNumber({0})", x); | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment