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.
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
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
defining Properties - syntax of all variations
whoops ! - sorry !!
seem to have chopped my last message before the end.
I have gotten the full Property definition OK I think :-
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.
seem to have chopped my last message before the end.
I have gotten the full Property definition OK I think :-
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
Hi Phil,
with the "auto" you get effectively a backingfield - that means the compiler creates itself the storage for the variable.
This X# code
generates this code:
Wolfgang
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
defining Properties - syntax of all variations
Hi Phil,
basically I know about 3 different property formats:
the standard one:
where you can of course omit the get or the set block.
And then is the short form (which I like most)
and you can omit there also the set or the get block.
And as last there is the automatic property:
And all the modifiers like static, protect, private, public are admitted too.
Wolfgang
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
And then is the short form (which I like most)
Code: Select all
property Phil as string get _cPhil set _cPhil := value
And as last there is the automatic property:
Code: Select all
property Phil as string auto
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
defining Properties - syntax of all variations
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.
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
Hi Phil,
only to add something: in my ViewModels that implement the INotifyPropertyChanged interface, I have this form of property:
because these inherit from my ExpandoBase class with the relative get/set methods that send also the notification.
Wolfgang
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>()
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it