This forum is meant for questions and discussions about the X# language and tools
leon-ts
Posts: 435 Joined: Fri Feb 03, 2017 1:43 pm
Post
by leon-ts » Sat Aug 07, 2021 6:27 pm
Hi,
I read in the X# documentation in the "PROPERTY Statement" section about the possibility to specify an
INIT accessor.
Quote from X# documentation:
INIT accessor declare that a property can only be changed in the constructor of a class. A property cannot have both a SET and an INIT accessor.
Wrote the code:
Code: Select all
CLASS MyClass
PROPERTY MyProperty AS INT AUTO GET INIT
END CLASS
The compiler throws an error:
XS0518 Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported
What is the correct use of the
INIT keyword in a
PROPERTY declaration?
Best regards,
Leonid
Best regards,
Leonid
Chris
Posts: 4907 Joined: Thu Oct 08, 2015 7:48 am
Location: Greece
Post
by Chris » Sat Aug 07, 2021 6:55 pm
Hi Leonid,
This looks like either a compiler bug, or that the compiler requires a newer a .Net framework version. Which one do you have installed?
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
leon-ts
Posts: 435 Joined: Fri Feb 03, 2017 1:43 pm
Post
by leon-ts » Sat Aug 07, 2021 7:15 pm
Hi Chris,
I have Windows 10 installed which has .NET Framework 4.8 included.
In X# applications I develop, I specify TargetFramework = 4.7.2
Best regards,
Leonid
Best regards,
Leonid
robert
Posts: 4520 Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands
Post
by robert » Sat Aug 07, 2021 7:26 pm
Leonid,
The INIT keyword requires either .Net 5 or you will have to add the following class to your app:
Code: Select all
// This static class is needed when not compiling against .Net 5
BEGIN NAMESPACE System.Runtime.CompilerServices
INTERNAL STATIC CLASS IsExternalInit
END CLASS
END NAMESPACE
See also
https://github.com/X-Sharp/XSharpDev/bl ... g/R766.prg
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
leon-ts
Posts: 435 Joined: Fri Feb 03, 2017 1:43 pm
Post
by leon-ts » Sat Aug 07, 2021 7:35 pm
Robert,
Thanks a lot! It works!
Best regards,
Leonid
Best regards,
Leonid