1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
using GLib;
public class Sample : Object {
private string automatic { get; set; }
private string _name;
[Notify]
public string name {
get { return _name; }
set { _name = value; }
}
private string _read_only;
public string read_only {
get { return _read_only; }
}
public Sample (string name) {
this.name = name;
}
construct {
_automatic = "InitialAutomatic";
_read_only = "InitialReadOnly";
}
public void run() {
notify += (s, p) => {
stdout.printf("property `%s' has changed!\n",
p.name);
};
automatic = "TheNewAutomatic";
name = "TheNewName";
// The following statement would be rejected
// read_only = "TheNewReadOnly";
stdout.printf("automatic: %s\n", automatic);
stdout.printf("name: %s\n", name);
stdout.printf("read_only: %s\n", read_only);
stdout.printf("automatic: %s\n", automatic);
}
static int main (string[] args) {
var test = new Sample("InitialName");
test.run();
Maman.Bar.run ();
return 0;
}
}
class Maman.Foo : Object {
private int _public_base_property = 2;
public int public_base_property {
get {
return _public_base_property;
}
set {
_public_base_property = value;
}
}
}
class Maman.Bar : Foo {
public int public_property { get; set; default = 3; }
void do_action () {
stdout.printf (" %d %d", public_base_property, public_property);
public_base_property = 4;
public_property = 5;
stdout.printf (" %d %d", public_base_property, public_property);
}
public static void run () {
stdout.printf ("Property Test: 1");
var bar = new Bar ();
bar.do_action ();
stdout.printf (" 6\n");
}
}
|