U4-9743 - Models Builder minor / dealing with collisions

Created by Stephan 06 Apr 2017, 06:56:50 Updated by Shannon Deminick 10 Apr 2017, 04:05:19

Tags: Unscheduled

Subtask of: U4-9609

Currently when a property name collides with the class name we still generate the property and then models fail to compile, and this is confusing, we need an option to NOT generate the property (or comment it out with big warnings)

Comments

Stephan 07 Apr 2017, 08:57:27

PR: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/pull/141 (note: it's a MB code PR)

with this in place, two things are fixed:

1.

if a model class name is used in a static getter and could cause a collision, deal with it. Say we have a model class named "Content" which is used as a composion, then the generated code for a composed property would be:

///

/// ContentValue /// [ImplementPropertyType("contentValue")] public string ContentValue { get { return Content.GetContentValue(this); } }

And there would be a collision because Content here is also the Content property of IPublishedContent. This has been changed to output:

public string ContentValue { get { return Umbraco.Web.PublishedContentModels.Content.GetContentValue(this); } }

So, no more collision here.

2.

CSharp does not support having a class and one of its property sharing the same name. Meaning that if content type Foo has a property named Foo, the generated code fails to compile. In theory the backend should not allow this anymore, but when ppl upgrade old sites etc, and suddenly PureLive kicks in, everything breaks.

Now when generating PureLive models, the property is generated as:

/*

  • THIS PROPERTY CANNOT BE IMPLEMENTED, BECAUSE:
  • CSharp does not support naming the property with alias
  • "foo" with the same name as content type with alias
  • "foo". Consider using an attribute to assign a different
  • name to the property.

///

/// foo /// [ImplementPropertyType("foo")] public string Foo { get { return this.GetPropertyValue("foo"); } }

* */

So basically it's there in models.generated.cs (should somebody tries to find it) but commented out. And the site will not break. This is only for PureLive really, due to many sites breaking because of that situation - sites where ppl often don't care about models, and don't understand what's going on.

review: reproduce both situations and see what is generated.


Priority: Normal

Type: Task

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 7.5.13

Sprint: Sprint 56

Story Points:

Cycle: