Conversation
|
I am open to the general idea of what you're trying to achieve. I find the existing code for code gen in LinqToXsdCore is on the verge of becoming literally unmaintainable, so a clean break would be good. I encourage you to continue work on this. |
|
@mamift ok I'll pick it up. |
|
Forced push a rebase on current |
As the public apis of the generator are going to change massively, we might as well do a few binary breaking changes to the entry points.
|
@mamift My strategy for validating this PR is still to generate all schemas identically (besides whitespace changes) but I decided to take a minor change under certain settings, for the sake of simplicity. When rendering with public class TypeManager
{
public static Type GetRootType { .. }
public static TypeManager Instance { .. }
}I match this 1:1. When rendering with internal class TypeManager
{
public static Type GetRootType { .. }
public static TypeManager Instance { .. }
}CodeDom implementation actually generates I think that's fine because the generation can still easily be verified with the default BTW I did some progress on this, the TypeManager is now fully templated and CodeDom for it was removed. Obviously there's still a long way to go, but I'm slowly working my way through this. |
A long time ago I floated the idea of using text templates to generate code instead of CodeDom.
I finally got to do a prototype. This is not ready to merge but here's what already committed:
ScribanGlobals. Those methods are used inside the template to "extract" from CodeDom information about the model being generated.Please bear in mind the template is a proof of concept but it's not final. It could be better split in smaller parts, the model could have better names, we can add some comments, etc.
It's already somewhat capable, though. I have experimented with schema
Microsoft.Search.Query.xsdwhich is reasonably large and makes use of:stringIf you run the code on this branch, the generated code is exactly the same as the current generator if you ignore whitespace differences. I was not masochist enough to match whitespace 1:1. Generating exactly the same code helps ensure there is no regression.
Tip
There is a VS Code extension to highlight the Scriban syntax
What would be the next steps?
I was surprised how quickly I was able to put this together, which speaks in favor of templates.
I am also extremely tempted to modify the templates to improve generated code, something I never felt empowered to do in CodeDom. But I won't do that before a 1:1 match of every generated file is possible and merged. Improvements are planned but will come afterwards.
The big amount of work right now is to (1) remove CodeDom and generate a data-only equivalent model; (2) support all features, this prototype is far from complete.
Things that could be possible in the future but I don't envision in this PR:
@mamift That's a drastic change but I believe it's for the better. What do you think? Should I continue working on this?