xsharp.eu • ToString - not working with DYNAMIC ?
Page 1 of 1

ToString - not working with DYNAMIC ?

Posted: Mon Dec 11, 2017 9:58 am
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 720 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 720 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.

ToString - not working with DYNAMIC ?

Posted: Mon Dec 11, 2017 11:06 am
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

ToString - not working with DYNAMIC ?

Posted: Mon Dec 11, 2017 11:51 am
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 720 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.

ToString - not working with DYNAMIC ?

Posted: Tue Jan 29, 2019 1:00 pm
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

ToString - not working with DYNAMIC ?

Posted: Tue Jan 29, 2019 3:25 pm
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 720 times
Jamal

ToString - not working with DYNAMIC ?

Posted: Tue Jan 29, 2019 3:42 pm
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

ToString - not working with DYNAMIC ?

Posted: Tue Jan 29, 2019 4:01 pm
by Chris
Hi Stefan,
I must admit I was just caught by the same thing as well :)

Chris

ToString - not working with DYNAMIC ?

Posted: Tue Jan 29, 2019 4:09 pm
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

ToString - not working with DYNAMIC ?

Posted: Tue Jan 29, 2019 4:14 pm
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