limbo-works / Limbo.Umbraco.ModelsBuilder

Custom models builder for Umbraco.
MIT License
4 stars 3 forks source link

[ImplementPropertyType()] Attribute being ignored for customized property names #13

Closed hfloyd closed 2 years ago

hfloyd commented 2 years ago

I noticed that if I specify a custom name for a property, the property is always regenerated, even if the customized property is marked with the [ImplementPropertyType()] attribute.

For example:

MyType.cs:

    partial class MyType
    {
        [ImplementPropertyType("fAQCategories")]
        public new System.Collections.Generic.IEnumerable<string> FaqCategories 
            => this.Value<System.Collections.Generic.IEnumerable<string>>("fAQCategories");
    }

(Notice the updated name: "fAQCategories" -> "FaqCategories")

When I generate models, this is generated:

MyType.generated.cs:

...
        [ImplementPropertyType("fAQCategories")]
        public new System.Collections.Generic.IEnumerable<string> FAqcategories 
            => this.Value<System.Collections.Generic.IEnumerable<string>>("fAQCategories");
...

I would expect that if my custom partial includes a property with [ImplementPropertyType("fAQCategories")], then the generation code would skip that property alias entirely.

abjerner commented 2 years ago

Hi @hfloyd and again thanks for reporting these issues 👍

I actually tried making LMB a bit smarter, so it automatically checks whether a property exists in the partial with the same CLR name. In this particular case it doesn't due to the fAQ / Faq casing - as C# property name are case sensitive.

I can't remember whether it was my plan to also support [ImplementPropertyType]. It probably was, but then I never got around to adding it.

Anyways - I did a quick look through my code, and updated the right places, and now [ImplementPropertyType] is supported on the individual properties of your custom partial, and [IgnorePropertyType] is supported on the partial class it self.

I hope to push a new release later today that includes this fix. I haven't really settled on if and how I'm going to still support Umbraco 9 (seeing as you created this issue back in May), as there is also some time involved in doing that. So at least for now, this will only be released for the Umbraco 10 version of this package.

hfloyd commented 2 years ago

👏🏻