fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: defining Properties - syntax of all variations

defining Properties - syntax of all variations 1 year 3 months ago #1

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.
Attachments:

Please Log in or Create an account to join the conversation.

defining Properties - syntax of all variations 1 year 3 months ago #2

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.
Attachments:

Please Log in or Create an account to join the conversation.

defining Properties - syntax of all variations 1 year 3 months ago #3

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1406
  • Karma: 6
Hi Phil,

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

This X# code
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:


Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

defining Properties - syntax of all variations 1 year 3 months ago #4

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1406
  • Karma: 6
Hi Phil,

basically I know about 3 different property formats:

the standard one:
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)
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:
property Phil as string auto

And all the modifiers like static, protect, private, public are admitted too.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

defining Properties - syntax of all variations 1 year 3 months ago #5

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
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.

Please Log in or Create an account to join the conversation.

defining Properties - syntax of all variations 1 year 3 months ago #6

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1406
  • Karma: 6
Hi Phil,

only to add something: in my ViewModels that implement the INotifyPropertyChanged interface, I have this form of property:
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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

  • Page:
  • 1