Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate IEnumerable<SpecificType> for linked items elements with constraint #17

Closed
petrsvihlik opened this issue Apr 26, 2017 · 3 comments

Comments

@petrsvihlik
Copy link
Contributor

petrsvihlik commented Apr 26, 2017

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>.

@hades200082
Copy link
Contributor

You could do this for all types.

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() )

@petrsvihlik
Copy link
Contributor Author

petrsvihlik commented Nov 19, 2017

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 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
@petrsvihlik
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants