limbo-works / Limbo.Umbraco.ModelsBuilder

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

Adding model helper to source code to return related ContentType Alias #2

Closed hfloyd closed 2 years ago

hfloyd commented 2 years ago

This adds a constant to each generated model that provides the string Content Type alias so that "magic strings" can be avoided in various code applications

example usage:

posts = blog.DescendantsOrSelf(BlogPost.ModelTypeAlias);

instead of:

posts = blog.DescendantsOrSelf("blogPost");

abjerner commented 2 years ago

Thanks @hfloyd 👍

This looks great, although I might move it a bit around 😉

abjerner commented 2 years ago

I'm not sure how many that will actually look at the generated files, but I prefer having #pragma flags at the file level - then we'll disable the warnings for the entire file.

So in https://github.com/limbo-works/Limbo.Umbraco.ModelsBuilder/commit/07a00a21cd98b62d50fa9edbce469722247c190a, I've introduced a new WritePragma method. The default implementation has the #pragma warning disable 0109 that you added as well as #pragma warning disable 1591 (Missing XML comment for publicly visible type or member).

The ModelTypeAlias constant is now also handled by the new WriteConstants method.

hfloyd commented 2 years ago

Sounds good! I like the organization :-)