fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: ToString - not working with DYNAMIC ?

ToString - not working with DYNAMIC ? 1 year 6 months ago #3333

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
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.

ToString - not working with DYNAMIC ? 1 year 6 months ago #3335

  robert's Avatar robert Offline Posts: 969
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.

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

Last edit: by robert.

ToString - not working with DYNAMIC ? 1 year 6 months ago #3336

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
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.

ToString - not working with DYNAMIC ? 4 months 2 weeks ago #7235

  SHirsch's Avatar SHirsch Offline Posts: 109
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:

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

ToString - not working with DYNAMIC ? 4 months 2 weeks ago #7238

  Jamal's Avatar Jamal Offline Posts: 101
Hi Stefan,

Did you add a reference to the Microsoft.CSharp in the solution explorer. It is not enough to insert a USING statement.



Jamal
Attachments:

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

ToString - not working with DYNAMIC ? 4 months 2 weeks ago #7239

  SHirsch's Avatar SHirsch Offline Posts: 109
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

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

ToString - not working with DYNAMIC ? 4 months 2 weeks ago #7240

  Chris's Avatar Chris Offline Posts: 1137
Hi Stefan,
I must admit I was just caught by the same thing as well :)

Chris
XSharp Development Team
chris(at)xsharp.eu

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

ToString - not working with DYNAMIC ? 4 months 2 weeks ago #7241

  Jamal's Avatar Jamal Offline Posts: 101
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

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

Last edit: by Jamal. Reason: That's VS 2017 build 15.9.6

ToString - not working with DYNAMIC ? 4 months 2 weeks ago #7242

  SHirsch's Avatar SHirsch Offline Posts: 109
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

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

  • Page:
  • 1