Comments (8)
I want to override the interface property so it can return a different type on a base class. See #41.
from modelsbuilder.original.
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.
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.
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.
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.
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.
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.
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)
- Generating models using the VS extension can cause namespace issues HOT 3
- Cleaner csproj include generated files HOT 1
- Can't Rebuild Models After Deleting Document Type HOT 6
- Interface definition only generated when document type is in use HOT 1
- Request error: The URL returned a 404 (not found): /App_Plugins/ModelsBuilder/modelsbuilder.html HOT 1
- Provide option for generated code to use Language Fallback HOT 7
- ModelsBuilder API Generates first IPublishedElement then never finishes HOT 10
- VS Extension: Method not found: 'System.String Umbraco.ModelsBuilder.Building.Compiler.CreateValidIdentifier(System.String)' HOT 2
- v4: Repository shouldnt link to local nuget server
- v4: If Document type with Template is created Umbraco fails with save of Document Type
- Implemented property keeps being generated HOT 6
- ModelsBuilder on Umbraco v8.8 HOT 10
- v4: Generator should be swappable / extendable
- Generated Models missing PublishedElementModel on generated model.
- Stack Overflow when implementing same interface in generated and partial class
- VS Extension install issue
- Execute ModelsBuilder Programmatically
- When generating models for IPublishedElement it adds a controller no matter what
- UmbracoModelsBuilder: UmbracoModelsBuilder failed to generate code: NullReferenceException HOT 1
- VS2022 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modelsbuilder.original.