Skip to end of metadata
Go to start of metadata

The previous example from the ProcessMethodBodiesWithDuckTyping step had a closure that accessed (and modified) an outside variable (clickcount).

Here a class is created to share that object.

import System.Windows.Forms from System.Windows.Forms

[Boo.Lang.ModuleAttribute]
public final transient class TempModule(System.Object):

	private static def Main(argv as (System.String)) as System.Void:
		___locals = TempModule.___locals3()
		f = System.Windows.Forms.Form()
		___locals.___clickcount_0 = 0
		b = __eval__(
                   (___temp1 = System.Windows.Forms.Button()), 
                    ___temp1.set_Text('Hello'), 
                    ___temp1.set_Dock(System.Windows.Forms.DockStyle.Fill), 
                    ___temp1)
		b.add_Click({ Boo.Lang.Builtins.print(
                    "you clicked me ${(
                      ___locals.___clickcount_0 = (
                      ___locals.___clickcount_0 + 1)
                     )} times") })
		f.get_Controls().Add(b)
		f.ShowDialog()

	private def constructor():
		super()

	internal static def ___closure2() as System.Void:
		Boo.Lang.Builtins.print(
                   "you clicked me ${(
                      ___locals.___clickcount_0 = (
                       ___locals.___clickcount_0 + 1)
                    )} times")

	class ___locals3(System.Object):

		internal ___clickcount_0 as System.Int32

		public def constructor():
			super()
  • No labels