/// <summary> /// A shorthand way to create an output object once /// the display model has been mapped. /// </summary> /// <param name="displayModel">The fully mapped display model.</param> public PageBlockTypeDisplayModelMapperOutput CreateOutput(IPageBlockTypeDisplayModel displayModel) { if (displayModel == null) { throw new ArgumentNullException(nameof(displayModel)); } if (VersionBlockId < 1) { throw new ArgumentOutOfRangeException(nameof(VersionBlockId)); } return(new PageBlockTypeDisplayModelMapperOutput() { DisplayModel = displayModel, VersionBlockId = VersionBlockId }); }
/// <summary> /// Adds a mapped model to the result collection. /// </summary> /// <param name="inputDataModel"> /// The input data model that the display model is mapped from. This is /// used to track which block the mapped display model represents. /// </param> /// <param name="mappedDisplayModel"> /// The mapped display model to render in the view. This should not /// be null; if the input cannot be mapped then exclude it from the /// result entirely. /// </param> public void Add(PageBlockTypeDisplayModelMapperInput <TDataModel> inputDataModel, IPageBlockTypeDisplayModel mappedDisplayModel) { if (inputDataModel == null) { throw new ArgumentNullException(nameof(inputDataModel)); } if (mappedDisplayModel == null) { throw new ArgumentNullException(nameof(mappedDisplayModel), "When mapping block data the display model should not be null, if the input cannot be mapped then exclude it from the result entirely."); } if (_mappedDisplayModels.ContainsKey(inputDataModel.VersionBlockId)) { throw new Exception($"The specified block model has already been added to the result. VersionBlockId {inputDataModel.VersionBlockId}, model type '{mappedDisplayModel.GetType()}'"); } _mappedDisplayModels.Add(inputDataModel.VersionBlockId, mappedDisplayModel); }