/*========================================================================================================================== | METHOD: INVOKE \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Assembles the view model for the <see cref="FilePathViewComponent"/>. /// </summary> public IViewComponentResult Invoke( EditingTopicViewModel currentTopic, FilePathAttributeDescriptorViewModel attribute, string htmlFieldPrefix ) { /*------------------------------------------------------------------------------------------------------------------------ | Validate parameters \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(currentTopic, nameof(currentTopic)); Contract.Requires(attribute, nameof(attribute)); /*------------------------------------------------------------------------------------------------------------------------ | Set HTML prefix \-----------------------------------------------------------------------------------------------------------------------*/ ViewData.TemplateInfo.HtmlFieldPrefix = htmlFieldPrefix; /*------------------------------------------------------------------------------------------------------------------------ | Establish view model \-----------------------------------------------------------------------------------------------------------------------*/ var model = new FilePathAttributeViewModel(currentTopic, attribute) { InheritedValue = GetInheritedValue(attribute.Key!, attribute) }; /*------------------------------------------------------------------------------------------------------------------------ | Set model values \-----------------------------------------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------------------------------------------ | Return view with view model \-----------------------------------------------------------------------------------------------------------------------*/ return View(model); }
/*========================================================================================================================== | METHOD: GET INHERITED VALUE \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Crawls up the tree to identify the source of inheritance (if available) and sets the value based on the base path /// defined by the parent (assuming <see cref="AttributeViewModel.InheritedValue"/> is enabled) and the relative path /// between that topic and the current topic (assuming <see cref="FilePathAttributeDescriptorViewModel.RelativeToTopicPath /// "/> is enabled). /// </summary> public string GetInheritedValue(string attributeKey, FilePathAttributeDescriptorViewModel attribute) { var inheritedValue = ""; if (attribute is { InheritValue: true, RelativeToTopicPath: true }) {