This repository was archived by the owner on Mar 13, 2026. It is now read-only.
Draft
Conversation
First somewhat working sample
* Fix transitive dependencies in source generator * Add changes to sample app for it to work. * Add fixes suggested by Visual Studio
Member
Member
Author
|
Yes, That seems rather obvious to me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
dataModelBindingsfrom 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/Apptemplate 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
.dllfrom a.Testproject, so unit testing is pretty easy.Notes
This PR includes a new project
Altinn.App.ModelGeneratorand a corresponding.Testproject. The ModelGenerator will be referenced fromApp.csprojwith some special attributes, and mapping the json files asAdditionalFilesso they become availible in the compilation.Actual usage
After adding the reference to the package, you can just delete your
[modelName].csfile, 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.