Table of Contents

Interface IContentQueryModelTypeMapper

Namespace
CMS.ContentEngine
Assembly
CMS.ContentEngine.dll

Mapper which provides automatic mapping of IContentQueryDataContainer to content type model registered via RegisterContentTypeMappingAttribute.

public interface IContentQueryModelTypeMapper
Extension Methods

Remarks

The interface could be extended in the future and does not support custom implementation.

Methods

Map<TModel>(IContentQueryDataContainer)

Maps the content query result IContentQueryDataContainer to a model of type TModel.

TModel Map<TModel>(IContentQueryDataContainer dataContainer)

Parameters

dataContainer IContentQueryDataContainer

IContentQueryDataContainer containing data to be mapped to the model.

Returns

TModel

TModel Model with mapped data from the dataContainer.

Type Parameters

TModel

Type of returned model.

Remarks

The mapping process follows this priority:

  1. If a model type is registered for the content type via RegisterContentTypeMappingAttribute and TModel is assignable from the registered type, the registered type is used for mapping.
  2. Otherwise, TModel is used directly for mapping, but it must be a non-abstract class with a parameterless constructor.
The properties of the model are mapped case insensitive by the name, so their names and types need to match the names and types in dataContainer except for special cases:
  • ContentItemFields property is mapped by type.
  • Linked items are mapped to System.Collections.Generic.IEnumerable<T> property.
Properties which are not included in the dataContainer will not be mapped.

Exceptions

ArgumentNullException

Thrown when container is null.

InvalidOperationException

Thrown when the data cannot be bound to the model e.g., the types of the properties doesn't match, the model type does not have parameterless constructor, when more types are registered to one content type name, or when TModel is abstract class or does not have a parameterless constructor.