Skip to content

Instantly share code, notes, and snippets.

@kg
Created June 7, 2011 08:12
Show Gist options
  • Save kg/1011876 to your computer and use it in GitHub Desktop.
Save kg/1011876 to your computer and use it in GitHub Desktop.
JSIL Code Sample: MulticastDelegates
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);
}
}
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