Hi guys,
Can anyone please suggest some X# syntax to express the following C# class ? :-
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.
HELP please - syntax for new class ...... >>
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP please - syntax for new class ...... >>
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
Robert
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
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP please - syntax for new class ...... >>
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'.
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 :-
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.
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'.
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 :-
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.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP please - syntax for new class ...... >>
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 :-
I have made an attempt as seen below :-
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.
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 :-
I have made an attempt as seen below :-
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.
HELP please - syntax for new class ...... >>
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
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
XSharp Development Team
chris(at)xsharp.eu
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP please - syntax for new class ...... >>
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.
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.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP please - syntax for new class ...... >>
Hi again Chris,
Here is another code syntax snippet I will needs in the morning - original C# first :-
And now my not very clever attempt at X# :-
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.
Here is another code syntax snippet I will needs in the morning - original C# first :-
And now my not very clever attempt at X# :-
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.
HELP please - syntax for new class ...... >>
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
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
XSharp Development Team
chris(at)xsharp.eu
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP please - syntax for new class ...... >>
Chris,
thanks, done, and now things are looking OK.
May be back to you again soon ;-0)
Fingers crossed,
Phil.
Wales, UK.
thanks, done, and now things are looking OK.
May be back to you again soon ;-0)
Fingers crossed,
Phil.
Wales, UK.
HELP please - syntax for new class ...... >>
Phil
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 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
Code: Select all
New()
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{}
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
The Netherlands
robert@xsharp.eu