Created
March 20, 2012 14:25
-
-
Save kg/2136144 to your computer and use it in GitHub Desktop.
JSIL Code Sample: Generics and Nested Types
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 class Program { | |
public static void Main (string[] args) { | |
Console.WriteLine( | |
Battlestar<object>.instance.commander | |
); | |
} | |
} | |
class Battlestar<T> { | |
public string commander; | |
public static Battlestar<T> instance; | |
class Galactica : Battlestar<T> { | |
public Galactica () { | |
commander = "Adama"; | |
} | |
} | |
static Battlestar() { | |
Console.WriteLine(".cctor " + typeof(T)); | |
instance = new Galactica(); | |
} | |
} |
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.MakeClass($asm01.TypeRef("System.Object"), "Program", true, [], function ($) { | |
$.Method({Static:false, Public:true }, ".ctor", | |
$sig.make(1087103, null, [], []), | |
function Program__ctor () { | |
} | |
); | |
$.Method({Static:true , Public:true }, "Main", | |
$sig.make(1087101, null, [$jsilcore.TypeRef("System.Array", [$.String])], []), | |
function Program_Main (args) { | |
$asm01.System.Console.WriteLine($asm00.Battlestar$b1.Of($asm01.System.Object).instance.commander); | |
} | |
); | |
}); | |
JSIL.MakeClass($asm01.TypeRef("System.Object"), "Battlestar`1", false, ["T"], function ($) { | |
$.Method({Static:false, Public:true }, ".ctor", | |
$sig.make(1087102, null, [], []), | |
function Battlestar$b1__ctor () { | |
} | |
); | |
$.Field({Static:false, Public:true }, "commander", $.String); | |
$.Field({Static:true , Public:true }, "instance", $.Type); | |
$.Method({Static:true , Public:false}, ".cctor", | |
$sig.make(1087100, null, [], []), | |
function Battlestar$b1__cctor () { | |
$asm01.System.Console.WriteLine(JSIL.ConcatString(".cctor ", $asm00.Battlestar$b1.T.get(this))); | |
$asm00.Battlestar$b1.Of($asm00.Battlestar$b1.T.get(this)).instance = | |
new ($asm00.Battlestar$b1_Galactica.Of($asm00.Battlestar$b1.T.get(this))) (); | |
} | |
); | |
}); | |
JSIL.MakeClass($asm00.TypeRef("Battlestar`1", [new JSIL.GenericParameter("T", "Battlestar`1/Galactica")]), "Battlestar`1/Galactica", false, ["T"], function ($) { | |
$.Method({Static:false, Public:true }, ".ctor", | |
$sig.make(1087116, null, [], []), | |
function Galactica__ctor () { | |
$asm00.Battlestar$b1.Of($asm00.Battlestar$b1_Galactica.T.get(this)).prototype._ctor.call(this); | |
this.commander = "Adama"; | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment