-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enable support for nested generic types in Models Builder #21287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable support for nested generic types in Models Builder #21287
Conversation
…t nested generic types
|
Hi there @skttl, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
| public virtual global::System.Collections.Generic.IEnumerable<global::" + modelsBuilderConfig.ModelsNamespace + | ||
| @".Foo> Foo => this.Value<global::System.Collections.Generic.IEnumerable<global::" + | ||
| modelsBuilderConfig.ModelsNamespace + @".Foo>>(_publishedValueFallback, ""foo""); | ||
| public virtual global::System.Collections.Generic.IEnumerable<global::{foo}> Foo => this.Value<global::System.Collections.Generic.IEnumerable<global::{foo}>>(_publishedValueFallback, ""foo""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This amend to the test doesn't look right to me @skttl. This string needs to be valid C#. Seems like this will change:
IEnumerable<global::Umbraco.Cms.Web.Common.PublishedModels.Foo>
to:
IEnumerable<global::{foo}>
Which won't compile.
This is test code of course, but the test is no longer valid (even if it passes). And it makes me concerned that you having to change this test is masking a regression bug.
|
@skttl (and @leekelleher, as I see you are discussing this on leekelleher/umbraco-contentment#514) - as I found some issues with this proposal in, I've tackled the underlying issue in a different way in #21429. Can you let me know what you think please? If it looks OK, we could proceed with this I feel. |
|
My thinking was that it would probably be better if the tests were using the same TextBuilder method. But your fix looks fine to me too. |
Prerequisites
Description
This fixes an issue in ModelsBuilder, where it generates invalid C# if you have a value converter generating nested generic types. Eg. leekelleher/umbraco-contentment#514.
Instead of passing in a the type as a string, which then gets corrupted in the string replacements being made, it passes in the type, so the method that takes the type can generate the C# code correctly.
Previously, ModelsBuilder used a string-based parser for generics (
WriteClrType(StringBuilder, string)), which would split on commas and flatten inner generic arguments, producing invalid C# like:IEnumerable<Tuple<string>, string, string>Changes made:
Type-basedWriteClrType(StringBuilder, Type)method, which correctly preserves nested generics and tuples.WriteClrType(StringBuilder, string), which was broken for nested generics and no longer referenced anywhere.How to test:
Without this change it would have been
Note the syntax error after System.Tuple
I tried generating models on an existing site with this change, and it didn't change anything in the existing properties.