// 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.Razor.Compilation; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; namespace Microsoft.AspNetCore.Mvc.ApplicationParts { /// /// An for . /// public class CompiledPageFeatureProvider : IApplicationFeatureProvider { /// /// Gets the namespace for the type in the view assembly. /// public static readonly string CompiledPageManifestNamespace = "AspNetCore"; /// /// Gets the type name for the view collection type in the view assembly. /// public static readonly string CompiledPageManifestTypeName = "__CompiledRazorPagesManifest"; private static readonly string FullyQualifiedManifestTypeName = CompiledPageManifestNamespace + "." + CompiledPageManifestTypeName; /// public void PopulateFeature(IEnumerable parts, ViewsFeature feature) { foreach (var item in GetCompiledPageInfo(parts)) { feature.Views.Add(item.Path, item.CompiledType); } } /// /// Gets the sequence of from . /// /// The s /// The sequence of . public static IEnumerable GetCompiledPageInfo(IEnumerable parts) { return parts.OfType() .Select(part => CompiledViewManfiest.GetManifestType(part, FullyQualifiedManifestTypeName)) .Where(type => type != null) .Select(type => (CompiledPageManifest)Activator.CreateInstance(type)) .SelectMany(manifest => manifest.CompiledPages); } } }