xsharp.eu • PROPERTY with different GET and SET modifiers
Page 1 of 1

PROPERTY with different GET and SET modifiers

Posted: Fri May 18, 2018 7:31 am
by SHirsch
Hi,

in C# following code is valid (the set is protected)

Code: Select all

public Exception LastException { get; protected set; }
in ILSpy with X# is shown:

Code: Select all

public property LastException as Exception 
  getend get
  protected setend set
'getend' and 'setend' seems to be strange. But 'protected' as modifier for set is recognized.

Now my question, how to set different access modifiers for get and set?

Code: Select all

PUBLIC PROPERTY LastException AS Exception GET PROTECTED SET
results in XS0106: The modifier 'override' is not valid for this item

Regards,
Stefan

PS: This should not result in discussion how to do error handling. This is just a sample about property and modifiers.

PROPERTY with different GET and SET modifiers

Posted: Fri May 18, 2018 7:45 am
by FFF
Stefan,
the "getend" points you should re-download Fabrice' tool, there was initially a glitch which resulted in this oddity ;)
Have a look at: https://www.xsharp.eu/forum/public-prod ... lugin#4661

Regards
Karl

PROPERTY with different GET and SET modifiers

Posted: Fri May 18, 2018 7:49 am
by SHirsch
Hi Karl,

thanks. The new version shows exactly the syntax I had expected.

Code: Select all

	
public property LastException as Exception get protected set 
But results in error: XS0106: The modifier 'override' is not valid for this item

Regards,
Stefan

PROPERTY with different GET and SET modifiers

Posted: Fri May 18, 2018 8:08 am
by robert
Stefan,

- Is this in a class or an interface ?
- If it is in a class, Is the property LastException already defined in the parent class ?
- What is the compiler setting for "treat all methods as Virtual" (/vo3)
- Your property does not define a body. Do you want this to be an "auto" property ?

Robert

PROPERTY with different GET and SET modifiers

Posted: Fri May 18, 2018 8:25 am
by SHirsch
Hi Robert,

- Is this in a class or an interface ?
class

- If it is in a class, Is the property LastException already defined in the parent class ?
it has no parent class.

- What is the compiler setting for "treat all methods as Virtual" (/vo3)
none of the compiler settings is set


- Your property does not define a body. Do you want this to be an "auto" property ?
is some cases yes, in others no. Both does result in same message.

Source from app where this occured first:

Code: Select all

CLASS Config
    STATIC PRIVATE __instance AS Config  
    PRIVATE _ini AS KoelndataSoftware.Tools.IniFile
    
PUBLIC PROPERTY Ini AS KoelndataSoftware.Tools.IniFile 
    GET 
        RETURN SELF:_ini
    END
    PROTECTED SET 
        SELF:_ini := VALUE
    END
END 
....
END CLASS
Regards,
Stefan

PROPERTY with different GET and SET modifiers

Posted: Fri May 18, 2018 11:36 am
by Chris
Thanks Stefan, this is a bug indeed and I think I am seeing some more similar related issues. Will add a comprehensive sample in our test suite for Robert to take care of.

Chris