1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This software is subject to the Microsoft Public License (Ms-PL).
* A copy of the license can be found in the license.htm file included
* in this distribution.
*
* You must not remove this notice, or any other, from this software.
*
* ***************************************************************************/
namespace System.Web.Mvc {
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Web.Mvc.Resources;
public class ViewEngineCollection : Collection<IViewEngine> {
public ViewEngineCollection() {
}
public ViewEngineCollection(IList<IViewEngine> list)
: base(list) {
}
protected override void InsertItem(int index, IViewEngine item) {
if (item == null) {
throw new ArgumentNullException("item");
}
base.InsertItem(index, item);
}
protected override void SetItem(int index, IViewEngine item) {
if (item == null) {
throw new ArgumentNullException("item");
}
base.SetItem(index, item);
}
private ViewEngineResult Find(Func<IViewEngine, ViewEngineResult> cacheLocator, Func<IViewEngine, ViewEngineResult> locator) {
ViewEngineResult result;
foreach (IViewEngine engine in Items) {
if (engine != null) {
result = cacheLocator(engine);
if (result.View != null) {
return result;
}
}
}
List<string> searched = new List<string>();
foreach (IViewEngine engine in Items) {
if (engine != null) {
result = locator(engine);
if (result.View != null) {
return result;
}
searched.AddRange(result.SearchedLocations);
}
}
return new ViewEngineResult(searched);
}
public virtual ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName) {
if (controllerContext == null) {
throw new ArgumentNullException("controllerContext");
}
if (string.IsNullOrEmpty(partialViewName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "partialViewName");
}
Func<IViewEngine, ViewEngineResult> cacheLocator = e => e.FindPartialView(controllerContext, partialViewName, true);
Func<IViewEngine, ViewEngineResult> locator = e => e.FindPartialView(controllerContext, partialViewName, false);
return Find(cacheLocator, locator);
}
public virtual ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName) {
if (controllerContext == null) {
throw new ArgumentNullException("controllerContext");
}
if (string.IsNullOrEmpty(viewName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "viewName");
}
Func<IViewEngine, ViewEngineResult> cacheLocator = e => e.FindView(controllerContext, viewName, masterName, true);
Func<IViewEngine, ViewEngineResult> locator = e => e.FindView(controllerContext, viewName, masterName, false);
return Find(cacheLocator, locator);
}
}
}
|