fbpx

ToString - not working with DYNAMIC ?

More
1 year 1 month ago #1 by Phil Hepburn
ToString - not working with DYNAMIC ? was created 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 :-



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 :-



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.
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 1 month ago - 1 year 1 month ago #2 by Robert van der Hulst
Replied by Robert van der Hulst on topic ToString - not working with DYNAMIC ?
Phil,

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

This works if you include the Microsoft.CSharp Library
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
Last edit: 1 year 1 month ago by Robert van der Hulst.

Please Log in or Create an account to join the conversation.

More
1 year 1 month ago #3 by Phil Hepburn
Replied by Phil Hepburn on topic ToString - not working with DYNAMIC ?
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 :-



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.
Attachments:

Please Log in or Create an account to join the conversation.