File: PropertyRegistration.cs

package info (click to toggle)
gtk-sharp2 2.12.40-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 26,632 kB
  • sloc: xml: 351,292; cs: 26,444; sh: 4,228; ansic: 2,915; makefile: 1,288; perl: 1,179
file content (44 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (7)
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
// PropertyRegistration.cs - GObject property registration sample
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2008 Novell, Inc.

namespace GtkSamples {

	using System;

	public class TestObject : GLib.Object {

		public static int Main (string[] args)
		{
			GLib.GType.Init ();
			TestObject obj = new TestObject ();
			GLib.Value val = new GLib.Value (42);
			obj.SetProperty ("my_prop", val);
			val.Dispose ();
			if (obj.MyProp != 42) {
				Console.Error.WriteLine ("Property setter did not run.");
				return 1;
			}
			GLib.Value val2 = obj.GetProperty ("my_prop");
			if ((int)val2.Val != 42) {
				Console.Error.WriteLine ("Property set/get roundtrip failed.");
				return 1;
			}
			Console.WriteLine ("Round trip succeeded.");
			return 0;
		}

		int my_prop;

		[GLib.Property ("my_prop")]
		public int MyProp {
			get { return my_prop; }
			set { 
				my_prop = value;
				Console.WriteLine ("Property setter invoked.");
			 }
		}
	}
}