How to define anonymous types?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
HansjoergP
Posts: 142
Joined: Mon Jul 25, 2016 3:58 pm
Location: Italy

How to define anonymous types?

Post by HansjoergP »

To use Dapper you need anonymous types. How can you define these in X#? In C# the syntax is e.g. new {x = ‘test’}

Thanks
Hansjörg
FFF
Posts: 1589
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: How to define anonymous types?

Post by FFF »

A look for "anonymous" into X# help provides:

The syntax for an anonymous class is :
VAR o := CLASS { Name := "test", Value := "something" }

Is that, what you need?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
HansjoergP
Posts: 142
Joined: Mon Jul 25, 2016 3:58 pm
Location: Italy

Re: How to define anonymous types?

Post by HansjoergP »

Thanks. Yes this is what I need
User avatar
robert
Posts: 4551
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: How to define anonymous types?

Post by robert »

HansJoerg,
If you're filling an anonymous type from another object then you don't need to include the names

Code: Select all

CLASS {Customer.ID, Customer.Name, Customer.DateOfBirth}
This will use the names of the properties as name of the properties in the anonymous type.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
rwooters
Posts: 15
Joined: Fri Mar 04, 2016 10:56 pm

Re: How to define anonymous types?

Post by rwooters »

The syntax in X# is close but not exact:

X#: CLASS {x := "test"}
C#: new {x = ‘test’}
Post Reply