// 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 System.Reflection; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Mvc.ApplicationModels { /// /// Application model component for RazorPages. /// public class PageApplicationModel { /// /// Initializes a new instance of . /// public PageApplicationModel( PageActionDescriptor actionDescriptor, TypeInfo handlerType, IReadOnlyList handlerAttributes) : this(actionDescriptor, handlerType, handlerType, handlerAttributes) { } /// /// Initializes a new instance of . /// public PageApplicationModel( PageActionDescriptor actionDescriptor, TypeInfo declaredModelType, TypeInfo handlerType, IReadOnlyList handlerAttributes) { ActionDescriptor = actionDescriptor ?? throw new ArgumentNullException(nameof(actionDescriptor)); DeclaredModelType = declaredModelType; HandlerType = handlerType; Filters = new List(); Properties = new CopyOnWriteDictionary( actionDescriptor.Properties, EqualityComparer.Default); HandlerMethods = new List(); HandlerProperties = new List(); HandlerTypeAttributes = handlerAttributes; } /// /// A copy constructor for . /// /// The to copy from. public PageApplicationModel(PageApplicationModel other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } ActionDescriptor = other.ActionDescriptor; HandlerType = other.HandlerType; PageType = other.PageType; ModelType = other.ModelType; Filters = new List(other.Filters); Properties = new Dictionary(other.Properties); HandlerMethods = new List(other.HandlerMethods.Select(m => new PageHandlerModel(m))); HandlerProperties = new List(other.HandlerProperties.Select(p => new PagePropertyModel(p))); HandlerTypeAttributes = other.HandlerTypeAttributes; } /// /// Gets the . /// public PageActionDescriptor ActionDescriptor { get; } /// /// Gets the application root relative path for the page. /// public string RelativePath => ActionDescriptor.RelativePath; /// /// 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 => ActionDescriptor.ViewEnginePath; /// /// Gets the area name. /// public string AreaName => ActionDescriptor.AreaName; /// /// Gets the route template for the page. /// public string RouteTemplate => ActionDescriptor.AttributeRouteInfo?.Template; /// /// Gets the applicable instances. /// public IList Filters { get; } /// /// Stores arbitrary metadata properties associated with the . /// public IDictionary Properties { get; } /// /// Gets or sets the of the Razor page. /// public TypeInfo PageType { get; set; } /// /// Gets the declared model of the model for the page. /// Typically this will be the type specified by the @model directive /// in the razor page. /// public TypeInfo DeclaredModelType { get; } /// /// Gets or sets the runtime model of the model for the razor page. /// This is the that will be used at runtime to instantiate and populate /// the model property of the page. /// public TypeInfo ModelType { get; set; } /// /// Gets the of the handler. /// public TypeInfo HandlerType { get; } /// /// Gets the sequence of attributes declared on . /// public IReadOnlyList HandlerTypeAttributes { get; } /// /// Gets the sequence of instances. /// public IList HandlerMethods { get; } /// /// Gets the sequence of instances on . /// public IList HandlerProperties { get; } } }