modelsbuilder / ModelsBuilder.Original

The Community Models Builder for Umbraco
MIT License
114 stars 49 forks source link

Warning if using property that hides inherited member #70

Closed ryanlewis closed 2 years ago

ryanlewis commented 8 years ago

Minor issue here, maybe a wontfix, but thought I'd jot this down.

Essentially, I have a property called "Content" on my document. This is less than ideal knowing the API, but ModelsBuilder generates a property for it and everything works as expected for now (may possibly break some third-party components, but haven't encountered any issues myself). The compiler complains with the warning below however.

'ContentPage.Content' hides inherited member 'PublishedContentWrapped.Content'. Use the new keyword if hiding was intended.

Maybe allow an attribute to be added to the partial impl of the class to instruct the models builder to use the new keyword in instances like this, to avoid compiler errors? This way you have to be explicit to enable this behaviour.

ryanlewis commented 8 years ago

Another possibility maybe just to add a #pragma (might be 0108) directive to kill the compiler warnings.

zpqrtbnk commented 8 years ago

So... the partial would look like...

[HidesInherited("myProperty")]
public partial class MyModel
{ }

And then we would generate either the new keyword, or a proper #pragma, so that the compiler does not raise a warning - and it has to be explicit because we cannot let you replace existing properties without even beeing aware of it.

Making sense?

ryanlewis commented 8 years ago

Yep, something like that is exactly what I'm thinking - making perfect sense to me.

zpqrtbnk commented 8 years ago

Request for comment:

[GeneratePropertyType("content", AsNew = true)]
public partial class MyContent
{ ... }

Would add the new keyword to the Content property so it does not conflict with the inherited propery. Could also be used for other IPublishedContent properties such as sortOrder, index... obviously, you'd use at your own risk ;-)

ryanlewis commented 8 years ago

Works just as well, possibly even better instead of another attribute to document. 👍

zpqrtbnk commented 8 years ago

Note: implemented in a work-in-progress branch, to be part of the "next" major.