xsharp.eu • Implicit Namespace for own libraries/XIDE
Page 1 of 1

Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 7:19 am
by wriedmann
Hi Chris/Robert,
I would like to add the possibility to use the implicit namespace compiler option also for some of my own libraries.
In the X# documentation is mentioned that there is an attribute

Code: Select all

[assembly: VulcanImplicitNamespaceAttribute( "SomeNameSpace )]
but in the sources there is a reference to a ImplicitNameSpaceAttribute:
https://www.xsharp.eu/runtimehelp/html/ ... ribute.htm
Maybe the help could be adjusted.

And how do I use that with XIDE?

Wolfgang

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 8:47 am
by Chris
Hi Wolfgang,

In XIDE, you just simply specify the global (implicit) namespace in app properties, general, Global Namespace.

Where exactly is the reference to VulcanImplicitNamespaceAttribute in the help file so we can change it? This was the ones used in vulcan (and in X# in the old days, when we were using the vulcan runtime through BYOR).

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 9:31 am
by wriedmann
Hi Chris,
the reference is in the /ins compiler option page in the X# help file.

About the namespace: it does not seems to work:
PostgreSQLHelper.png
and gives this error
CompileError.png
Wolfgang

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 9:40 am
by Chris
Hi Wolfgang,

The Global Namespace option needs to be used in the library where you want to prefix all classes with that namespace.

In order to use that library from another app/library without prefixing types with the default namespace, you need to enable the /ins option (in app properties, compiler page) in this app/library. It's the same thing as if you are using the VOSDK libraries, you need to specify the /ins option in apps using it, otherwise you need to type names with the namespace "VO".

Or do you mean that this still doesn't work? Which dialect are you using?

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 9:46 am
by wriedmann
Hi Chris,
The Global Namespace option needs to be used in the library where you want to prefix all classes with that namespace.
Yes, I know that and I'm using that alle the time in my Core dialect libraries and applications.
n order to use that library from another app/library without prefixing types with the default namespace, you need to enable the /ins option (in app properties, compiler page) in this app/library. It's the same thing as if you are using the VOSDK libraries, you need to specify the /ins option in apps using it, otherwise you need to type names with the namespace "VO".
In my application I do use the /ins compiler option, and in fact I do not have to specify the VO namespace.
But to use the class from my library I have to use the using statement.

As far as I understand to make the work I have to use the special attribute ImplictitNameSpaceAttribute for the compiler.

Wolfgang

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 10:15 am
by Chris
Hi Wolfgang,

If the library is using the Core dialect, then indeed you need to specify it in the code:

USING XSharp.Internal

[assembly: ImplicitNamespace("MyGlobalNamespace")]

And both this library and any apps/libraries using it must have a reference to XSharp.Core, as this is where the attribute is defined.

I think need to make some improvements to the compiler and documentation about this...Firstly the compiler should report an error when the /ns (prefix types with global namespace) and/or /ins options are used without having a reference to XSharp.Core, as currently doing that results to silently failing to set/use a global namespace. Then the documentation should describe all this much better. Will open tickets for both.

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 11:04 am
by wriedmann
Hi Chris,
thank you very much!
This way it works.
Wolfgang
P.S. since one of the libraries we would like to use this manner is a COM library that we also use from VO, we have opted to not do that because otherwise would also need to distribuite and load the XSharp.Core library

Re: Implicit Namespace for own libraries/XIDE

Posted: Tue Oct 29, 2024 11:11 am
by Chris
Hi Wolfgang,

If I remember correctly, we had considered using one of the system attributes for that instead, in order to avoid introducing a dependency to XSharp.Core for core dialect apps. But could not find an appropriate already existing in the framework attribute for that...