kontent-ai / model-generator-net

Kontent.ai .NET model generator.
https://www.nuget.org/packages/Kontent.Ai.ModelGenerator
MIT License
17 stars 19 forks source link

Known types - LI element limited to multiple types with 1 item #160

Open Sevitas opened 1 year ago

Sevitas commented 1 year ago

Motivation

Solves scenario 3 of issue #90 scenarios Linked items element limited to multiple types with at least 1 at most or exactly 1 item.

Proposed solution

Article.Generated.cs will contain

public IEnumerable<IContentItem> Attachement { get; set; }

Article.Typed.Generated.cs will contain

public Image AttachementImageSingle => Attachement.OfType<Image>().FirstOrDefault();
public Other AttachementOtherSingle => Attachement.OfType<Other>().FirstOrDefault();

Additional context

As a developer, you still need to check which property contains a value. Other properties will contain a null. Take in mind responses and notes in the comment.