xsharp.eu • defining Properties - syntax of all variations
Page 1 of 1

defining Properties - syntax of all variations

Posted: Mon Dec 18, 2017 2:01 pm
by Phil Hepburn
Hi Team and all Forum guys,

I am adding a sub-section to the 'ClickStartXSharp' eNotes on Properties and the correct syntax to use to define them. I wish to include all variations.
XSprops_01.jpg
XSprops_01.jpg (51.03 KiB) Viewed 257 times
I see from the release notes that 'auto' adds a field to support the property. What is its name ?

If I use the one line 'get set' variation, does this do the same as 'auto' - do I get a backing field?

Enough for now, more later perhaps.

defining Properties - syntax of all variations

Posted: Mon Dec 18, 2017 2:06 pm
by Phil Hepburn
whoops ! - sorry !!

seem to have chopped my last message before the end.

I have gotten the full Property definition OK I think :-
XSprops_02.jpg
XSprops_02.jpg (115.11 KiB) Viewed 257 times
Can anyone suggest other variations that I may have missed while making the two images in this post and my last one ?

Cheers,
Phil.
Wales, UK.

defining Properties - syntax of all variations

Posted: Mon Dec 18, 2017 2:16 pm
by wriedmann
Hi Phil,

with the "auto" you get effectively a backingfield - that means the compiler creates itself the storage for the variable.

This X# code

Code: Select all

class Properties
protect _cValue			as string
	
constructor()
	
_cValue	:= ""
	
return
	
property FullForm as string
  get
    return _cValue
  end get
  set
    _cValue := value
  end set
end property

property ShortForm as string get _cValue set _cValue := value
property AutoProperty as string auto
	
end class
generates this code:
properties.png
properties.png (9.21 KiB) Viewed 257 times
Wolfgang

defining Properties - syntax of all variations

Posted: Mon Dec 18, 2017 2:31 pm
by wriedmann
Hi Phil,

basically I know about 3 different property formats:

the standard one:

Code: Select all

property Phil as string
  get
    return _cPhil
  end get
  set
    _cPhil := value
  end set
end property
where you can of course omit the get or the set block.

And then is the short form (which I like most)

Code: Select all

property Phil as string get _cPhil set _cPhil := value
and you can omit there also the set or the get block.

And as last there is the automatic property:

Code: Select all

property Phil as string auto
And all the modifiers like static, protect, private, public are admitted too.

Wolfgang

defining Properties - syntax of all variations

Posted: Mon Dec 18, 2017 3:37 pm
by Phil Hepburn
Thanks a lot Wolfgang,

I will work with this in the eNotes.

What you have written adds a couple more things to what I already had found. So well done.

Regards,
Phil.

defining Properties - syntax of all variations

Posted: Mon Dec 18, 2017 3:44 pm
by wriedmann
Hi Phil,

only to add something: in my ViewModels that implement the INotifyPropertyChanged interface, I have this form of property:

Code: Select all

public property ConfigImage as string set self:_Set<string>( value ) get self:_Get<string>()
because these inherit from my ExpandoBase class with the relative get/set methods that send also the notification.

Wolfgang