[Gtk-sharp-list] Gtk.Label set_Text()

Jonathan Pryor jonpryor@vt.edu
Sun, 19 Oct 2003 11:19:44 -0400


Just as a follow up, where are you seeing "set_Text", anyway?  Monodoc
just shows "Text".

For future reference, CIL has a formalized "name mangling" scheme, so
that languages that don't have support for properties, events, and
operator overloading can still invoke the underlying functions.

A property declaration:

	int Property {
		get {return 1;}
		set {}
	}

is renamed in the underling CIL to a "get_" or set_" prefix followed by
the property name:

	int get_Property ();
	void set_Property (int value);

However, in languages that support properties, you call the above
functions using field-access syntax:

	obj.Property = 42;	// calls set_Property (int);
	int n = obj.Property;	// calls get_Property ();

Events use "add_" and "remove_" prefixes; "add_" uses += syntax in C#,
while "remove_" uses -= syntax in C#.  Note that specifying add and
remove blocks in the event is optional; if not present, a default event
implementation is provided.

	event EventHandler FooEvent;
	event EventHandler BarEvent {
		add {/* do something */}
		remove {/* do something else */}
	}
	obj.FooEvent += new EventHandler (func);// calls add_FooEvent
	obj.FooEvent -= new EventHandler (func);// calls remove_FooEvent

Operator overloading is mangled into "op_" + English description of
operation, for example op_Add for operator+, op_Subtract for operator-,
etc.  More detail is provided in the ECMA standard documents.

The only time you really need to worry about any of this is when
programming in a language that doesn't have support for these features,
for example Microsoft J#, which must directly call the property, event,
and operator overloading functions (as it lacks support for those
language features).

 - Jon

On Sun, 2003-10-19 at 07:55, Jonathan Pryor wrote:
> It's a property, so you don't call it as a function, you call it as if
> it were a member named without the "set_":
> 
> 	Label l = new Label ();
> 	l.Text = "some text in a label";  // calls Widget.set_Text()
> 
>  - Jon
> 
> On Sun, 2003-10-19 at 02:37, Joe Scaduto wrote:
> > I am having trouble with widget.set_Text() where widget is a Gtk.Label
> > widget.  When I run mcs I get error cs0571: set_Text cannot call
> > operator or accessor.  Does anyone know what this means or how I can fix
> > this?
> > 
> > Thanks
> > 
> > Joe
> > 
> > _______________________________________________
> > Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list