// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Mvc.ApplicationModels { /// /// A model component for routing RazorPages. /// public class PageRouteModel { /// /// Initializes a new instance of . /// /// The application relative path of the page. /// The path relative to the base path for page discovery. public PageRouteModel(string relativePath, string viewEnginePath) : this(relativePath, viewEnginePath, areaName: null) { } /// /// Initializes a new instance of . /// /// The application relative path of the page. /// The path relative to the base path for page discovery. /// The area name. public PageRouteModel(string relativePath, string viewEnginePath, string areaName) { RelativePath = relativePath ?? throw new ArgumentNullException(nameof(relativePath)); ViewEnginePath = viewEnginePath ?? throw new ArgumentNullException(nameof(viewEnginePath)); AreaName = areaName; Properties = new Dictionary(); Selectors = new List(); RouteValues = new Dictionary(StringComparer.OrdinalIgnoreCase); } /// /// A copy constructor for . /// /// The to copy from. public PageRouteModel(PageRouteModel other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } RelativePath = other.RelativePath; ViewEnginePath = other.ViewEnginePath; AreaName = other.AreaName; Properties = new Dictionary(other.Properties); Selectors = new List(other.Selectors.Select(m => new SelectorModel(m))); RouteValues = new Dictionary(other.RouteValues, StringComparer.OrdinalIgnoreCase); } /// /// Gets the application root relative path for the page. /// public string RelativePath { get; } /// /// Gets the path relative to the base path for page discovery. /// /// This value is the path of the file without extension, relative to the pages root directory. /// e.g. the for the file /Pages/Catalog/Antiques.cshtml is /Catalog/Antiques /// /// /// In an area, this value is the path of the file without extension, relative to the pages root directory for the specified area. /// e.g. the for the file Areas/Identity/Pages/Manage/Accounts.cshtml, is /Manage/Accounts. /// /// public string ViewEnginePath { get; } /// /// Gets the area name. Will be null for non-area pages. /// public string AreaName { get; } /// /// Stores arbitrary metadata properties associated with the . /// public IDictionary Properties { get; } /// /// Gets the instances. /// public IList Selectors { get; } /// /// Gets a collection of route values that must be present in the /// for the corresponding page to be selected. /// /// /// /// The value of is considered an implicit route value corresponding /// to the key page. /// /// /// The value of is considered an implicit route value corresponding /// to the key area when is not null. /// /// /// These entries will be implicitly added to /// when the action descriptor is created, but will not be visible in . /// /// public IDictionary RouteValues { get; } } }