2sxc 17 comes with a brand new system to generate code for you, making life easier. Introducing the 2sxc Copilot 🧑✈️.
Background
2sxc has a long journey behind it going from
- dynamic code - where you could write BlogPost.PublishDate - but you needed to guess what you could write and what type you would get, since it was treated as dynamic. And if you wrote BlogPost.DublishPate it would just return null and depending on your code fail. But if your code was inside an if-statement and not running when you tested it, you would never notice.
- to typed code - where you would write BlogPost.DateTime("PublishDate") - still requiring knowledge of the exact properties, but at least it was typed (.net and VS Code knew it was going to be a DateTime) and you would get an error if you used BlogPost.DateTime("DublishPate"). So it was better, but not perfect. No IntelliSense could tell you what properties existed, and the wrapped-in-if still applied.
- to strong-typed code with full IntelliSense - so you could write BlogPost.PublishDate again, and it was strictly typed to being a DateTime, + it would also throw an exception at compile time if you made a typo
This Requires Real C# Code
For this to work, there must be C# classes which define these objects and properties. Otherwise neither VS Code nor the Roslyn compiler would be able to know that these properties exist, and what they do.
To be specific, in needs code that looks a bit like this - for every ContentType in your App:
The example above is trivial - two string properties - but I assume you can see where this is going. It requires a lot of lines of code, and it must also be maintained as your code changes.
Introducing the 2sxc Copilot
We would like to welcome our new Copilot to the 2sxc features team. It's an assistant that will generate (and regenerate) all kinds of code for you, making sure you don't have to do it. Here's what the UI looks like:
The Copilot will generate:
- C# classes for all your ContentTypes - and use methods which are really clever and allow you to extend the classes as you need.
- C# classes for Razor - so that you can also use strong-typed App.Settings.MySetting and other neat tricks
- C# classes for custom services
- C# classes for custom WebApis
The whole system is very advanced - especially the ContentType generator. We've spent a lot of resources into making it seamless and smart. For example, a property Author will return a single object of the correct type (eg. AppCode.Data.Author) while a property Tags will get you an IEnumerable<AppCode.Data.Tag>.
Here's an example showing generated files as well as manually created partial code files (the selected ones) which extend the functionality while still allowing for the generated files to be auto-replaced:
We've documented what it does extensively, so you best check out the docs.
How To Use
Just install the latest 2sxc (17.06+) and you will find the copilot under the section Data as well as under Views. We'll add more variants soon. Just run it, and watch the magic.
If you're using Polymorphism, the copilot will detect the editions you specify in the app.json file and let you generate new models (eg. in Staging) so you can do Open-Heart-Surgery and develop in secret while not affecting the live environment.
Examples
In the next few days we'll start to release our standard apps using the latest conventions, so you can easily grow into it. Have fun!
Love from Switzerland,
iJungleboy