HELP please - syntax for new class ...... >>

This forum is meant for anything you would like to share with other visitors
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP please - syntax for new class ...... >>

Post by Phil Hepburn »

Hi guys,

Can anyone please suggest some X# syntax to express the following C# class ? :-
HelpForum_01.jpg
HelpForum_01.jpg (56.26 KiB) Viewed 641 times
And for those how give me a hard time over images V text, here is some text to use :-

public abstract class GenericDataSourceBase<DSO, VMO, MAPPER, DAL> : IGenericDataSource<VMO>
where MAPPER : IGenericVMMapper<DSO, VMO>, new()
where VMO : IDSObjectWithState
where DSO : IDSObjectWithState
where DAL : IGenericDAL<DSO>, new()
{
// method to get a single object by its primary key
public virtual DSResult<VMO> GetData(int dataid)

Just to keep you in the picture, the translation of Nick friend's C# Generic Data, EF6 and MVVM sample app is progressing nicely. A lot of work before we seen any tangible results however ;-0)

TIA,
Phil.
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

HELP please - syntax for new class ...... >>

Post by robert »

Phil,

Look at: https://www.xsharp.eu/help/class.html
and
https://www.xsharp.eu/help/generic-types.html

for the syntax.

It will become something like

Code: Select all

CLASS GenericDataSourceBase<DSO, VMO, MAPPER, DAL> IMPLEMENTS IGenericDataSource ;
   WHERE MAPPER IS IGenericVMMapper<DSO, VMO>, NEW();
   WHERE VMO IS IObjectWithState ;
   WHERE DSO IS IObjectWithState ;
   WHERE DAL IS IGenericDAL<DSO>, New()

.
.
END CLASS
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP please - syntax for new class ...... >>

Post by Phil Hepburn »

Thanks Robert,

Got me on my way, and past the parser and compiler.

Out of interest the image shows the last line has 'IS' and not 'is'.
parserCS_01.jpg
parserCS_01.jpg (40.47 KiB) Viewed 641 times
This is simply because when I tried to Build I got an error message regarding the same.

When I just there now tried to regenerate the error message to show you, the 'is' compiled OK !?

Here it is :-
parserCS_02.jpg
parserCS_02.jpg (50 KiB) Viewed 641 times
I have more C# I need help with - but later. Am going to see some sport on my new Sky Sport 'Q' box.

Thanks again for your help so far.

Oh! I thought 'new()' was a C# way of instantiating - what does it mean to X# guys ?

Cheers,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP please - syntax for new class ...... >>

Post by Phil Hepburn »

Thanks Robert,

I am getting there okay it seems - BUT - there is some strange C# code (to me) in this code to deal with Generics and Nicks' data.

Can you help me with this :-
syntaxCS_03.jpg
syntaxCS_03.jpg (82.97 KiB) Viewed 641 times
I have made an attempt as seen below :-
syntaxCS_04.jpg
syntaxCS_04.jpg (99.07 KiB) Viewed 641 times
And so you can have text to work with below is both the X# and the original C# :-

============================================================================
public virtual method GetDataAsync(dataid as int) as Task<DSResult<VMO>>

return Task.Factory.StartNew<DSResult<VMO>>( { || ;
local result as DSResult<VMO>
try
local implied dal := DAL{}
local efdata := dal.DALGetData(dataid) as DSResult<DSO>

if (efdata.Result == DSResultType.Success)
local implied mapper := MAPPER{}
result := DSResult<VMO>{mapper.DSOtoVMO(efdata.Cargo)}
else
result := DSResult<VMO>{efdata.Result}
endif
catch e as Exception
result := DSResult<VMO>{DSResultType.Otherfailure, e}
end try
return result
} )
return result

========================================================================
public virtual Task<DSResult<VMO>> GetDataAsync(int dataid)
{
return Task.Factory.StartNew<DSResult<VMO>>(() =>
{
DSResult<VMO> result;
try
{
DAL dal = new DAL();
DSResult<DSO> efdata = dal.DALGetData(dataid);
if (efdata.Result == DSResultType.Success)
{
MAPPER mapper = new MAPPER();
result = new DSResult<VMO>(mapper.DSOtoVMO(efdata.Cargo));
}
else
{
result = new DSResult<VMO>(efdata.Result);
}
}
catch (Exception e)
{
result = new DSResult<VMO>(DSResultType.Otherfailure, e);
}
return result;
});
}Cheers,
==========================================================================================

TIA,

Phil.
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

HELP please - syntax for new class ...... >>

Post by Chris »

Hi Phil,

Just remove the ";" from the end of the first "return" line (3rd line of those you posted). All that code that follows the return statement is an anonymous method and we have decided that anonymous method's lines should not be separated with ";" (otherwise you would have to add a semicolon at the end of _every_ line).

Also remove the final "RETURN" (it's redundant, that anonymous method is what is already is being returned by the GetDataAsync method) and it should compile fine.

And yes, providing the source code was extremely helpful in testing my suggestions and making sure I am not saying something stupid :)

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP please - syntax for new class ...... >>

Post by Phil Hepburn »

Thanks Chris,

Seems to compile fine and give no red lines, wavy or straight ;-0)

I will be back with another small syntax issue or two in the morning.

But what you have just put straight for me I can also apply to a few more methods and new class or two, so BIG thanks !

Cheers,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP please - syntax for new class ...... >>

Post by Phil Hepburn »

Hi again Chris,

Here is another code syntax snippet I will needs in the morning - original C# first :-
ChrisSyntax2_01.jpg
ChrisSyntax2_01.jpg (59.18 KiB) Viewed 641 times
And now my not very clever attempt at X# :-
ChrisSyntax2_02.jpg
ChrisSyntax2_02.jpg (57.06 KiB) Viewed 641 times
And finally some of my code for you to copy and paste :-

============================================================
public interface IGenericDataSource<VMO>
GetData(dataid as int) as DSResult<VMO>
FetchDataList() as DSResult<List<VMO>>
UpdateDB(DataAction edittype, VMO dataobject) as DSResult<VMO>

GetDataAsync(dataid as int) as Task<DSResult<VMO>>
FetchDataListAsync() as Task<DSResult<List<VMO>>>
UpdateDBAsync(edittype as DataAction, dataobject as VMO) as Task<DSResult<VMO>>
end interfaceCheers,
========================================================================================

Once again, if I get an answer to this I will be able to apply it in many places ;-)

Best regards,
Phil.
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

HELP please - syntax for new class ...... >>

Post by Chris »

Hi Phil,

You just need to put the METHOD keyword before each method name in the interface definition. Also adjust the parameters of the UpdateDB() method (they currently use the c# syntax in you sample) and it should compile fine.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP please - syntax for new class ...... >>

Post by Phil Hepburn »

Chris,

thanks, done, and now things are looking OK.

May be back to you again soon ;-0)

Fingers crossed,
Phil.
Wales, UK.
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

HELP please - syntax for new class ...... >>

Post by robert »

Phil

Code: Select all

New()
is just an indication that the type has a public constructor without parameters.
We copied the C# term because we were not very creative at that time.

We should have probably changed it to

Code: Select all

New{}
in stead but I am sure that people would have more problems then converting C# code to X#. It is already complicated enough at this moment, especially for generic classes.

Maybe we should create a small tool that takes a block of C# code, parses it with Roslyn into a parse tree and then spits out X# code?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply