Coder Social home page Coder Social logo

Comments (8)

jbreuer avatar jbreuer commented on August 17, 2024

I want to override the interface property so it can return a different type on a base class. See #41.

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

At the moment attributes on a partial interface are ignored. In fact the interface is just the "interface view" of the underlying type. In other word, you have a type MyType, and because it's used in a composition we also generate interface IMyType. I tend to think that it's OK do ignore all attributes on the interface, because everything should be done on the type itself.

At the moment, [RenamePropertyType] applied to the type, will rename the property in the interface. However, [ImplementPropertyType] on a type's property will NOT change the property in the interface, and that's definitively a bug. Going to fix this, and then the proper way to achieve what you want would be to change the type property (and it would be mirrored in the interface).

Making sense?

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

More about it. ImplementPropertyType should be used on the type, not the interface. In fact attributes on the interface are ignored. So you define a custom implementation of the property, on the type. Then... it would be good if we could somehow derive the proper interface declaration for the property -- but I think this is going to be error-prone at best. Sooo what I propose is, once you ImplementPropertyType on a property on the type, it's not generated in the interface, and you also have to manually write the declaration in a partial interface.

This also means that the property needs to be manually implemented in any type that uses the composition type, because we cannot really figure out how to implement it in a reliable way (of course we could try to duplicate the implementation that you provide... but that's not always going to work...).

Thoughts?

from modelsbuilder.original.

jbreuer avatar jbreuer commented on August 17, 2024

How would this work when I want to use ImplementPropertyType on a base class that has the interface? Like I said in #41.

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

Say you have that type, Something, that's used in compositions UsingType1 and UsingType2. And Something has a property SomeProp that is an integer. By default, we would generate interface ISomething (defining int SomeProp), class Something (implementing int SomeProp), and then classes UsingType1 and UsingType2 (both declaring they implement ISomething, and actually implementing int SomeProp).

If I understand correctly you want SomeProp to, say, return a string instead of an integer. Initial idea was to do it on a partial interface, but we don't want to support attributes on interfaces... they have to be on the type itself, so you'd do...

public partial class Something
{
  [ImplementPropertyType("someProp")]
  public string SomeProp { get { ... } }
}

Because you implement the property by yourself, we don't generate it in the interface anymore, so you'd also need to do:

public partial interface ISomething
{
  string SomeProp { get; }
}

And because you implement the property by yourself, we don't generate it in UsingType1 or UsingType2 anymore. So you'd have to do:

public partial class UsingType1
{
  [ImplementPropertyType("someProp")]
  public string SomeProp { get { ... } }
}

And also in UsingType2. Assuming you have UsingType1...UsingType99 and you don't want to write the above code 99 times... you may want to write a base class looking like:

public class SomeProbBase : PublishedContentModel
{
  public SomeProbBase(IPublishedContent content) : base(content) {}

  [ImplementPropertyType("someProp")]
  public string SomeProp { get { ... } }
}

And then...

public partial class UsingType1 : SomeProbBase {}

Though you still have to repeat that line 99 times... Now it's obvious what you want, right? You want me to copy your implementation of that property over to each of the 99 classes automatically. Correct?

I have no idea if it can be done. Looking into it.

from modelsbuilder.original.

jbreuer avatar jbreuer commented on August 17, 2024

The above is already good. Implementing that line 99 times isn't a problem because most of the time the classes that I'm working with also need to override some other properties with ImplementPropertyType so they already exist.

So I think this will work :-).

from modelsbuilder.original.

zpqrtbnk avatar zpqrtbnk commented on August 17, 2024

Then it should work as of 2.1.0 in its current state. TBH I think that's better because trying to "cut and paste" your property from the original type to all the derived types... might be possible... but smells. Fine then, 2.1 should be out soon.

from modelsbuilder.original.

jbreuer avatar jbreuer commented on August 17, 2024

With Umbraco 7.4 everything is a composition so the above situation will happen a lot more. Should Umbraco really stop supporting base document types?

from modelsbuilder.original.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.