ToString - not working with DYNAMIC ?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

ToString - not working with DYNAMIC ?

Post by Phil Hepburn »

Hi Robert, Chris and Team,

I have a small problem / issue and need some help please.

I am researching Collections, LINQ and Lambda Expressions, with Anonymous Types, for my Cologne 2018 eNotes and also "ClickStartXSharp".

I have a method returning a DYNAMIC collection from a LINQ query. This is then bound to a 'DataGrid' on a WPF form - it seems to work nicely, as one of the images shows - see below :-
NoToStringDynamic_02.jpg
NoToStringDynamic_02.jpg (138.9 KiB) Viewed 396 times
Now then, all I wished to do was to see what Type of object I was passing by first showing on a MessageBox the result of a ToString() on the object passed. I thought that 'ToString()' always worked, with everything !?

Here is what I got from the compiler :-
NoToStringDynamic_01.jpg
NoToStringDynamic_01.jpg (113.54 KiB) Viewed 396 times
Please can you have a quick look at the images (and code) to see if I may be doing something silly or wrong. If there is a need for you to have code and script then I will send a full small project - I will make one from the test and trial code (currently messy) I have been working on.

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

ToString - not working with DYNAMIC ?

Post by robert »

Phil,

You need to add a reference to the assembly Microsoft.CSharp

This works if you include the Microsoft.CSharp Library

Code: Select all

FUNCTION Start() AS VOID
	LOCAL d AS DYNAMIC
	d := Person{}
	d:FirstName := "Phil"
	d:LastName  := "Hepburn"
	
	Console.WriteLine("Hello {0}", d)
	Console.ReadKey()

CLASS Person
	PROPERTY FirstName AS STRING AUTO
	PROPERTY LastName AS STRING AUTO
	METHOD ToString() AS STRING 
		RETURN FirstName+" "+LastName
	
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

ToString - not working with DYNAMIC ?

Post by Phil Hepburn »

Hi Robert,

THANKS for the quick reply - and I am now up and running.

I can now adjust my eNotes etc..

Here is a picture of success :-
NoToStringDynamic_12.jpg
NoToStringDynamic_12.jpg (51.68 KiB) Viewed 396 times
What was misleading me was that the original object printed out from inside the generating method, but then of course it was not of Type 'DYNAMIC'.

Thanks once again,
Cheers,
Phil.
Wales, UK.
User avatar
SHirsch
Posts: 284
Joined: Tue Jan 30, 2018 8:23 am

ToString - not working with DYNAMIC ?

Post by SHirsch »

Hi Robert,

I tried the code you provided, referenced Microsoft.CSharp.dll but I still get error XS0656 (see att.). What I am missing?

Compiler: 2.0.0.8
X#/Core
no compiler switches set

Regards,
Stefan
Attachments
XSharp_DynamicTest2.JPG
XSharp_DynamicTest2.JPG (60.81 KiB) Viewed 396 times
Jamal
Posts: 315
Joined: Mon Jul 03, 2017 7:02 pm

ToString - not working with DYNAMIC ?

Post by Jamal »

Hi Stefan,

Did you add a reference to the Microsoft.CSharp in the solution explorer. It is not enough to insert a USING statement.
1-29-2019 10-21-02 AM.jpg
1-29-2019 10-21-02 AM.jpg (47.72 KiB) Viewed 396 times
Jamal
User avatar
SHirsch
Posts: 284
Joined: Tue Jan 30, 2018 8:23 am

ToString - not working with DYNAMIC ?

Post by SHirsch »

Hi Jamal,

yes it was referenced. If not there would be error XS0234 (missing reference).
But System.Core also has to be referenced. Then it compiles and runs.

Stefan
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

ToString - not working with DYNAMIC ?

Post by Chris »

Hi Stefan,
I must admit I was just caught by the same thing as well :)

Chris
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Jamal
Posts: 315
Joined: Mon Jul 03, 2017 7:02 pm

ToString - not working with DYNAMIC ?

Post by Jamal »

Hi Stefan,

But System.Core is added automatically when you create a new project. How could it be missing?
I am using X# beta 8 with VS 2017 build 15.9.6

Jamal
User avatar
SHirsch
Posts: 284
Joined: Tue Jan 30, 2018 8:23 am

ToString - not working with DYNAMIC ?

Post by SHirsch »

Hi Jamal,

I am using XIDE. It's lightweight and also runs on Surface Go. I am using VS2017 only for C# and Visual Basic stuff.

Stefan
Post Reply