/// <summary> /// Casts the item to a model. /// </summary> /// <typeparam name="T">Type of the model.</typeparam> public T CastTo <T>() { return(_modelProvider.GetContentItemModel <T>(_source, _linkedItemsSource)); }
/// <summary> /// Initializes a new instance of the <see cref="DeliveryItemListingResponse{T}"/> class. /// </summary> /// <param name="response">The response from Kentico Kontent Delivery API that contains a list of content items.</param> /// <param name="modelProvider">The provider that can convert JSON responses into instances of .NET types.</param> internal DeliveryItemListingResponse(ApiResponse response, IModelProvider modelProvider) : base(response) { _modelProvider = modelProvider; _pagination = new Lazy <Pagination>(() => _response.Content["pagination"].ToObject <Pagination>(), LazyThreadSafetyMode.PublicationOnly); _items = new Lazy <IReadOnlyList <T> >(() => ((JArray)_response.Content["items"]).Select(source => _modelProvider.GetContentItemModel <T>(source, _response.Content["modular_content"])).ToList().AsReadOnly(), LazyThreadSafetyMode.PublicationOnly); _linkedItems = new Lazy <JObject>(() => (JObject)_response.Content["modular_content"].DeepClone(), LazyThreadSafetyMode.PublicationOnly); }
/// <summary> /// Initializes a new instance of the <see cref="DeliveryItemResponse{T}"/> class. /// </summary> /// <param name="response">The response from Kentico Kontent Delivery API that contains a content item.</param> /// <param name="modelProvider">The provider that can convert JSON responses into instances of .NET types.</param> internal DeliveryItemResponse(ApiResponse response, IModelProvider modelProvider) : base(response) { _modelProvider = modelProvider; _item = new Lazy <T>(() => _modelProvider.GetContentItemModel <T>(_response.Content["item"], _response.Content["modular_content"]), LazyThreadSafetyMode.PublicationOnly); _linkedItems = new Lazy <JObject>(() => (JObject)_response.Content["modular_content"].DeepClone(), LazyThreadSafetyMode.PublicationOnly); }