2sxc 16.03 is another big step in strictly typed code.
Summary
- We've massively improved the new typed mode introduced in 16.01 and 16.02.
- Note that this does introduce some small breaking changes to very new code - so it should not affect most users.
- Plus a lot of other enhancements
Typed Mode Very Strict by Default
The new typed mode should help developers detect problems during development and not at runtime. In addition to having a strictly typed C# API, we've now also ensured that getting any property such as FirstName or Birthday will also verify that this field exists. Here's why:
- We discovered a lot of code such as if (item.Bool("HasImage")) { ... } which was using fields that didn't even exist! This led us to believe that as code evolves, things are left over which don't do anything.
- We also discoved code where bad naming lead the developer to believe the item contained a different object than expected (eg. a Tag instead of a BlogPost).
We know that there are scenarios where you need a less-strict approach, eg. when looping through a list of items of different types (eg. Person and PersonExtended). This is still possible using (..., required: false) and other tricks.
Note that if you do access a field that doesn't exist, you'll get some really nice help, as shown in the image here:
📖 Read more about this in the docs
More Checking-APIs in Typed Mode
As things get more strict, so does the need for the C# code to check if a property exists and has useful content. We added the following APIs:
- ContainsKey(name)
- Keys() - lists all keys, or just specific ones
- IsEmpty(name)
- IsNotEmpty(name)
These are useful in many scenarios, so stay tuned for samples in the tutorial coming up soon.
More APIs in Typed Mode
- item.Picture(name, ...) is great for adding Picture tags, and much simpler than going through the previous Kit.Image.Picture(item.Field(name), ...) APIs
- The .String(name, scrubHtml: ...) was improved. You can now still provide true/false, or you can provide a list of tags such as "p" to only scrub specific tags from the HTML. This is great for teaser-texts and more.
- AsItem(..., mock: true) allows you to create virtual/fake/mock items, which have the same API like a real item, but with data that was invented in the code. This is great to provide alternate items when the query doesn't result with anything real.
- Json Wrappers like var jsonObj = Kit.Json.ToTyped(someJson) now support path queries, so you can do jsonObj.String("Parent.Child.Id") and more.
More Image Enhancements
- The ImageService on Kit.Image now can better handle IFile objects to automatically find descriptive metadata for an image and crop-configurations 💃🏽
- We now include a new settings preset called Square for - you guessed it - square images.
Error Help
A minor but helpful feature is that the error messages now try to spot your code file and mark it with a target emoji: 🎯. This will help you figure out problems even faster.
TL;DR
Get it now from Github releases ☁️.
Love from Switzerland, and Croatia,
iJungleboy