Mixing C# and X#

This forum is meant for questions and discussions about the X# language and tools
User avatar
Eric Selje
Posts: 31
Joined: Sun Sep 22, 2019 3:16 pm

Mixing C# and X#

Post by Eric Selje »

I was under the impression that I could mix C# and X# projects in one Solution. Is that incorrect?

Eric
User avatar
wriedmann
Posts: 3752
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Mixing C# and X#

Post by wriedmann »

Hi Eric,
you can do that. In one solution, different applications.
One or more libraries can be in C# (or VB.NET), and your X# application can use them.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Eric Selje
Posts: 31
Joined: Sun Sep 22, 2019 3:16 pm

Mixing C# and X#

Post by Eric Selje »

So if I had a XAML application with C# back-end code, and wanted to use my X# business objects, could I combine them in one solution, or would I create two solutions and reference the X# libraries from my XAML app?
User avatar
wriedmann
Posts: 3752
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Mixing C# and X#

Post by wriedmann »

Hi Eric,
if you combine them in one solution or not is just a question of taste.
Of course you can having a C# WPF application use your X# business objects - but only if they obey to the C# rules: no untyped parameters, no parameter skipping, no untyped variables.
Try and play with it.... after all, the X# compiler writes IL code like the C# compiler.
I'm doing similar things all the time, but not with C# (as I don't like it), but with applications written in X# Core dialect using X# VO style libraries.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Eric Selje
Posts: 31
Joined: Sun Sep 22, 2019 3:16 pm

Mixing C# and X#

Post by Eric Selje »

Ah - I think I see now what I was doing wrong. I was trying to stick C# code into a project that I had created using the X# WPF Application Template. I need to create a new project from the C# WPF Application Template so I get the correct compiler settings.

Thanks for talking me through this!

Eric
User avatar
wriedmann
Posts: 3752
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Mixing C# and X#

Post by wriedmann »

Hi Eric,
exactly!
The greatest advantage of X# is that it takes your xBase code into the .NET platform. That makes it unique and invaluable - and therefore we should do what we can to keep the development team alive and working on it.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
TimothyS
Posts: 62
Joined: Thu Dec 15, 2016 3:39 pm
Location: Australia

Mixing C# and X#

Post by TimothyS »

I have been mixing X# and C# projects for some time now. The C# facility is useful for sample code for 3rd party interfaces. It saves having to translate to X#. C# is quite good, but it is hard to go past X# for flexibility and productivity.
Usually, I will reference the C# projects from my X# projects, but you can do the other way if you follow the rules mentioned by Wolfgang.

Regards,
Tim
info@task.si
Posts: 31
Joined: Mon Nov 02, 2015 2:08 pm

Mixing C# and X#

Post by info@task.si »

Hi everybody !
Encouraged by last web conference .NET 5.0 - X# core (https://www.youtube.com/watch?v=PJVq_IwzcO8) and positive response from Robert on my question about mixing X# code and Blazor (Razor) code I started to mix C#, X# core DLL and Blazor code. First tests are very impressive and I will continue to develop my first web oriented application.
I choose Blazor because I am a newbie in .net world and I must start from zero. I have also requests from my customers to upgrade my ERP subsystem which was written mainly in VO code to WEB and of course that Blazor is capable also for Linux and MacOS operating system.
At that point I must also thank to you Wolfgang, and to Danilo Gulliano who also adressed those problems and possibility.

At last I have a request. Can anybody warn us and appoint me on the obstacles or dangerouses in a real (production) world. Must X# code be in Core dialect ?
Can I mix Dbcontext and ADO.NET (X# Core dialect library) to reach the data in MS SQLServer ?
Best Regards Andrej Terkaj
User avatar
wriedmann
Posts: 3752
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Mixing C# and X#

Post by wriedmann »

Hi Andrej,
congratulations to your application!
First: you don't have to use only the X# Core dialect, but what you export to your C# application should use what C# knows. That means only typed methods, no VO style arrays, no codeblocks and no date values.
Second: of course you can mix DbContext and Ad.NET.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
info@task.si
Posts: 31
Joined: Mon Nov 02, 2015 2:08 pm

Mixing C# and X#

Post by info@task.si »

Thank you Wolfgang !

I understand. I already implemented SMTP class in X#.DLL and then called from Blazor. I have now warnings from VisualStudio about await (async) states. I will try to solve this problem.

What would you recommend us when we want to access X# arrays. We can convert array to <List> and then it can be returned to C#. But I am using also multidimensional arrays and as far as I know there is no substitution for it in C#.

My plan is to use SqlClient (ADO.NET) in my future X# library for some functions and methods (i.e. -- Let me return last ID # from SQL table ... because i am familiar with Robert's VO2ADO library ). For all other purposes DbContext seems is more convenient.

Regards Andrej Terkaj
Post Reply