fbpx

defining Properties - syntax of all variations

More
1 year 1 month ago #1 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.



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.

More
1 year 1 month ago #2 by Phil Hepburn
Replied by Phil Hepburn on topic 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.
Attachments:

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

More
1 year 1 month ago #3 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic 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
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
Attachments:

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

More
1 year 1 month ago #4 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic defining Properties - syntax of all variations
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

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

More
1 year 1 month ago #5 by Phil Hepburn
Replied by Phil Hepburn on topic 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.

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

More
1 year 1 month ago #6 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic 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:
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

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