AsList(some-list) replaces AsDynamic(some-list) in 2sxc Razor and WebApi. This will make your code shorter and more readable. Discover the new AsList(...)!
Why a new AsList(...) API
Previously 2sxc used
- the default lists usually like
var links = AsDynamic(Data["Default"]);
- lists like
var personList = AsDynamic(Data["Persons"]);
- single items like
var person = AsDynamic(personList.First());
The first issue was with LINQ in Razor, which is dynamically typed. The main issue was that LINQ commands like
.Select(...) need to know that they are being attached to an
AsDynamic(...) might return a single item or a list, the compiler would complain in the above example
personList.First(). In the end you would write something like
(personList as IEnumerable<dynamic>).First() - which was just ugly.
The second issue was that there were a LOT of
AsDynamic(Data["Default"]) which will now just be a simpler
How to get AsList(...)
We want to motivate people to use the RazorComponent base class for all new Razor work, slowly deprecating the older implementation. So to benefit from AsList, you'll need to make your razor file a RazorComponent. Once you make the switch, previous
AsDynamic(list) won't work any more. Single-item use like
AsDynamic(item) will continue to work.
Note that you need 2sxc 10.20.06 :)