[Kde-bindings] Passing blocks to constructors in Qyoto

Arno Rehn arno at arnorehn.de
Mon Jun 29 15:00:49 UTC 2009


On Monday 29 June 2009 13:30:29 Richard Dale wrote:
> Just seen a code snippet on this blog which has a block being passed to a
> UILabel constructor:
>
> http://tirania.org/blog/archive/2009/Jun-29.html
>
> UILabel l = new UILabel(new CGRect(50, 50, 230, 100)) {
>     Text = "Hello from MonoTouch";
> };
>
> I've found it is really useful to be able to do that in QtRuby.
>
> Would it be possible to do that in Qyoto? Does it need a very new version
> of Mono to work?
It's already possible. It's a C# language features and is available since C# 
3.0, called "object initializers".

QPushButton pb = new QPushButton() {
	Text = "foo",
	WindowTitle = "bar"
};

Note that you have to use commas and can only assign properties. Passing real 
blocks to constructors like you can in Ruby isn't possible, afaik.

-- 
Arno Rehn
arno at arnorehn.de



More information about the Kde-bindings mailing list