You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Blocked: We need the content type API endpoint to return the information about content element constraints
Motivation
If a linked items element is limited to accept only items of specific types, we should be able to reflect that in generated models.
Design guidelines
If it is constrained to a single content type, we should be able to generate its property as IEnumerable<SpecificType> instead of IEnumerable<object>. If the element is constrained to several content types, we could somehow allow the developer to associate the property with an interface, which would make the generator always create the property of type IEnumerable<Interface>.
The text was updated successfully, but these errors were encountered:
Define an interface - something like IListableObject and set that in the IEnumerable. Then just have all generated models implement that interface.
A method of the interface (and thus generated in each class - or using a base abstract class) could return a properly cast object based on the system.type property. (e.g. myListableObject.AsType() )
The content items in IEnumerable<object> are already strongly typed.
So you can do e.g.
public IEnumerable<object> LinkedContentItems {get;set;}
...
var articles = LinkedContentItems.OfType<Article>();
I would rather not introduce any more complexity to the type system. (And one thing we wanted to avoid from the beginning is inheritance - we wanted POCO models.) You can extend the existing models by using partial classes (if you want) but this is not something we should generate by default. Or do you think otherwise?
petrsvihlik
changed the title
Generate IEnumerable<SpecificType> for modular content elements with constraint
Generate IEnumerable<SpecificType> for linked items elements with constraint
Nov 5, 2018
Blocked: We need the content type API endpoint to return the information about content element constraints
Motivation
If a linked items element is limited to accept only items of specific types, we should be able to reflect that in generated models.
Design guidelines
If it is constrained to a single content type, we should be able to generate its property as
IEnumerable<SpecificType>
instead ofIEnumerable<object>
. If the element is constrained to several content types, we could somehow allow the developer to associate the property with an interface, which would make the generator always create the property of typeIEnumerable<Interface>
.The text was updated successfully, but these errors were encountered: