public TDisplayModel MapDetails <TDisplayModel>(CustomEntityRenderDetails dataModel) where TDisplayModel : ICustomEntityDisplayModel { var mapperType = typeof(ICustomEntityDetailsDisplayModelMapper <,>).MakeGenericType(dataModel.Model.GetType(), typeof(TDisplayModel)); var mapper = _resolutionContext.Resolve(mapperType); var method = mapperType.GetMethod("MapDetails"); return((TDisplayModel)method.Invoke(mapper, new object[] { dataModel, dataModel.Model })); }
/// <summary> /// Maps custom entity render data into a specific custom entity /// display model type, which can be used to render out view data. /// </summary> /// <typeparam name="TDisplayModel">Display model type to map to.</typeparam> /// <param name="renderDetails">The custom entity model to map, including the raw data model.</param> /// <param name="publishStatusQuery"> /// The query type that should be used to query dependent entities. E.g. if the custom /// entity was queried with the Published status query, then any dependent entities should /// also be queried as Published. /// </param> /// <returns>Mapped display model instance.</returns> public Task <TDisplayModel> MapDisplayModelAsync <TDisplayModel>( CustomEntityRenderDetails renderDetails, PublishStatusQuery publishStatusQuery ) where TDisplayModel : ICustomEntityDisplayModel { var mapperType = typeof(ICustomEntityDisplayModelMapper <,>).MakeGenericType(renderDetails.Model.GetType(), typeof(TDisplayModel)); var mapper = _serviceProvider.GetRequiredService(mapperType); var method = mapperType.GetMethod(mapDisplayModelMethodName); return((Task <TDisplayModel>)method.Invoke(mapper, new object[] { renderDetails, renderDetails.Model, publishStatusQuery })); }