Hello again Robert,
Sorry, I have had a few days away from LINQ 'stuff' doing some house maintenance - replacing floor boards in a bedroom !! What a task.
However, I do have something positive to post, on the issue of 'in-line' instantiation. Since your last post, I had a play around and a think, and used the current compiler facilities to come up with some better, tidier, and easier to read syntax. The three attached and inserted small images will help explain all. Sorry the 'system' has inserted them in the reverse order to my selection, so checkout '_01' first, then '_02' and '_03'.
By naming the Constructor variables 'in_xxxx' where the X's represent the exact property names, then the code all gets a lot more understandable.
Hope this makes sense, but I would still prefer to use an empty Constructor and then specify (in any order) the property name and the value to be assigned. This way we can effectively have all possible overloads, as zero to 'N' inputs can be provided.
Regards to all,
Phil.
Instantiation syntax - our own Classes etc.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
Instantiation syntax - our own Classes etc.
Whoops ! - an Addendum :-
The last image shows that we can only be as tight in our code as our human frailties (inabilities) allows us to be.
If you check out the commented code and its related part, you see we can assign incorrectly as long as the type is correct, and the compiler is none the wiser ;-0)
Regards,
Phil.
The last image shows that we can only be as tight in our code as our human frailties (inabilities) allows us to be.
If you check out the commented code and its related part, you see we can assign incorrectly as long as the type is correct, and the compiler is none the wiser ;-0)
Regards,
Phil.
Instantiation syntax - our own Classes etc.
Phil,
You will be pleased to hear that we have added object initializers and collection initializers for the next build.
An example of the collection initializer:
An example of the Object Initializer, with a nested collection initializer for the Phones property.
Please also note that an AUTO property can have an initial value too, without a constructor !)
Robert
You will be pleased to hear that we have added object initializers and collection initializers for the next build.
An example of the collection initializer:
Code: Select all
FUNCTION Start AS VOID
LOCAL a AS ArrayList
a := ArrayList{}{1,2,3}
? a[1]
Console.Read()
Please also note that an AUTO property can have an initial value too, without a constructor !)
Code: Select all
FUNCTION Start AS VOID
VAR oPerson := Person{}{ Last := "Van Der Hulst", First :=
"Robert", Phones := {"123","456"} }
? oPerson
Console.Read()
CLASS Person
PROPERTY First AS STRING AUTO
PROPERTY Last AS STRING AUTO
PROPERTY Phones AS List<STRING> AUTO := List<STRING>{}
METHOD ToString() AS STRING
VAR result := First+" "+Last
FOREACH VAR p IN Phones
result += " P: "+p
NEXT
RETURN result
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
Instantiation syntax - our own Classes etc.
Hi Robert,
This sounds really good, and also a VERY worthwhile step forward. I look forward to using it when you make it publically available. I certainly will have it in my examples and eNotes for Cologne.
For the moment I have plenty to keep me busy, apart from my floor replacement tasks ;-0)
Next on my list is to look at "LINQ to SQL" and create some X# samples and eLearning notes. There are a few things which differentiate LINQ to SQL from "LINQ to Objects", even though the basic / fundamental syntax code has many similarities.
Please give my best wishes to all the Team.
Cheers,
Phil.
P.S. I will make a note in my session material of what you posted - just so they know what is coming soon.
This sounds really good, and also a VERY worthwhile step forward. I look forward to using it when you make it publically available. I certainly will have it in my examples and eNotes for Cologne.
For the moment I have plenty to keep me busy, apart from my floor replacement tasks ;-0)
Next on my list is to look at "LINQ to SQL" and create some X# samples and eLearning notes. There are a few things which differentiate LINQ to SQL from "LINQ to Objects", even though the basic / fundamental syntax code has many similarities.
Please give my best wishes to all the Team.
Cheers,
Phil.
P.S. I will make a note in my session material of what you posted - just so they know what is coming soon.