// 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.Collections.Generic; using System.Linq; using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Mvc.ViewEngines { /// public class CompositeViewEngine : ICompositeViewEngine { /// /// Initializes a new instance of . /// /// The options accessor for . public CompositeViewEngine(IOptions optionsAccessor) { ViewEngines = optionsAccessor.Value.ViewEngines.ToArray(); } /// public IReadOnlyList ViewEngines { get; } /// public ViewEngineResult FindPartialView( [NotNull] ActionContext context, [NotNull] string partialViewName) { return FindView(context, partialViewName, partial: true); } /// public ViewEngineResult FindView( [NotNull] ActionContext context, [NotNull] string viewName) { return FindView(context, viewName, partial: false); } private ViewEngineResult FindView( ActionContext context, string viewName, bool partial) { var searchedLocations = Enumerable.Empty(); foreach (var engine in ViewEngines) { var result = partial ? engine.FindPartialView(context, viewName) : engine.FindView(context, viewName); if (result.Success) { return result; } searchedLocations = searchedLocations.Concat(result.SearchedLocations); } return ViewEngineResult.NotFound(viewName, searchedLocations); } } }