www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Properties in C# and prop_Foo

reply Bill Baxter <wbaxter gmail.com> writes:

The syntax

int Thing {
   get { return _thing; }
   set { _thing = value; }
}



int prop_Thing() { return _thing; }
void prop_Thing(int value) { _thing = value; }

Just thought it was interesting given all our discussions,

was proposing we use for D's syntax.  And I think I even said that was
fine, but let's have a different syntax for declaring that the D
compiler translates into those prop_Thing methods.  Well, it turns out


--bb
Aug 08 2009
parent reply grauzone <none example.net> writes:
Bill Baxter wrote:

 The syntax
 
 int Thing {
    get { return _thing; }
    set { _thing = value; }
 }
 

 
 int prop_Thing() { return _thing; }
 void prop_Thing(int value) { _thing = value; }
 
 Just thought it was interesting given all our discussions,

 was proposing we use for D's syntax.  And I think I even said that was
 fine, but let's have a different syntax for declaring that the D
 compiler translates into those prop_Thing methods.  Well, it turns out

set_Thing and get_Thing, btw.). It also creates and associates metadata with the property (so that you know that "Thing" is supposed to be a property with these setters and getters). it's just that on the lowest level, it is mapped to normal methods + extra metadata. That's probably not quite what was proposed.
 --bb
Aug 09 2009
parent reply Bill Baxter <wbaxter gmail.com> writes:
On Sun, Aug 9, 2009 at 11:25 AM, grauzone<none example.net> wrote:
 Bill Baxter wrote:

 The syntax

 int Thing {
 =A0 get { return _thing; }
 =A0 set { _thing =3D value; }
 }



 int prop_Thing() { return _thing; }
 void prop_Thing(int value) { _thing =3D value; }

 Just thought it was interesting given all our discussions,

 was proposing we use for D's syntax. =A0And I think I even said that was
 fine, but let's have a different syntax for declaring that the D
 compiler translates into those prop_Thing methods. =A0Well, it turns out

set_Thing and get_Thing, btw.). It also creates and associates metadata w=
ith
 the property (so that you know that "Thing" is supposed to be a property
 with these setters and getters).


t's
 just that on the lowest level, it is mapped to normal methods + extra
 metadata.
I see. I thought you could call get_Thing, set_Thing directly. --bb
Aug 09 2009
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Sun, 09 Aug 2009 15:53:23 -0400, Bill Baxter <wbaxter gmail.com> wrote:

 On Sun, Aug 9, 2009 at 11:25 AM, grauzone<none example.net> wrote:
 Bill Baxter wrote:

 The syntax

 int Thing {
   get { return _thing; }
   set { _thing = value; }
 }



 int prop_Thing() { return _thing; }
 void prop_Thing(int value) { _thing = value; }

 Just thought it was interesting given all our discussions,

 was proposing we use for D's syntax.  And I think I even said that was
 fine, but let's have a different syntax for declaring that the D
 compiler translates into those prop_Thing methods.  Well, it turns out

set_Thing and get_Thing, btw.). It also creates and associates metadata with the property (so that you know that "Thing" is supposed to be a property with these setters and getters). it's just that on the lowest level, it is mapped to normal methods + extra metadata.
I see. I thought you could call get_Thing, set_Thing directly.
It used to be in C++.NET (at least the .NET 1.0 version) you HAD to call/define properties that way ;) I think they've since added syntax to C++.Net to have more friendly property access. I'm not sure if you can still call the get_/set_ versions, but knowing Microsoft's propensity for backwards compatibility, you probably can... though I've never found a need to. One possible reason is to pass it as a delegate. -Steve
Aug 10 2009