Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a very early work in process where I try to explore the feasibility of using Source generators to generate a C# model that supports all the
dataModelBindings
from the Layout files. This means that for development (at least) we can just add components in the layout definitions in json, and the corresponding C# class will be included in the compilation and used by InteliSense in both VS 2022 and VS code.As a shortcut for easy testing I modified the
src/App
template to be a valid app with layouts I could use for testing. This would obviously need to be removed before merging.The current code generation is very rudimentary and needs a lot of work. The main focus was to ensure that compilation and IntelliSense worked, and to get a feel for the development process. Because the generator needs to run as part of VisualStudio/Omnisharp it is a lot harder to develop this kind of functionality than I imagined. Fully automatic testing would also be hard, as the errors are different when running in VS/VSCode/dotnet commandline, so there would need to be a manual routine to ensure that everything works everywhere before relasing new versions. The generator can be referenced as a normal
.dll
from a.Test
project, so unit testing is pretty easy.Notes
This PR includes a new project
Altinn.App.ModelGenerator
and a corresponding.Test
project. The ModelGenerator will be referenced fromApp.csproj
with some special attributes, and mapping the json files asAdditionalFiles
so they become availible in the compilation.Actual usage
After adding the reference to the package, you can just delete your
[modelName].cs
file, and all your references in DataProcessing and Instantiation will continue to work as the model is now autogenerated. When you add newdataModelBindings
, they will automatically be part of the model.Known remaining issues
Transitive dependencies for the generator
The generator needs to parse Json, and I opted for
System.Text.Json
. It has a few dependencies, and for some unknown reason a Source generator needs to reference all transitive dependencies as in the following section.