Search code examples
sitecoreglass-mapper

How to retrieve a collection of fields in Glass model?


Is it possible to retrieve a collection of fields as a property of a mapped glass model ? For example, I have a "Product" item in Sitecore with a collection of custom "Product Attribute" fields. I'd like to be able to access these fields as a collection through which I can enumerate, without explicitly naming the fields in my glass model. This way I can then add more attributes and enumerate them in code, without changing the glass model code.

Something like the following:

[SitecoreInfo(SitecoreInfoType.Fields)]
public virtual IEnumerable<something> Attributes { get; set; }

Many thanks.


Solution

  • Without any more specifics, it sounds like you may want to implement a Glass Mapper data handler via AbstractSitecoreFieldMapper for your custom type.