public NoMvcViewEngineExtensions(VirtualPathProviderViewEngine viewEngine, INoMvcViewLocationFormatsProvider viewLocationFormatsProvider) { if (viewEngine == null) throw new ArgumentNullException("viewEngine"); if (viewLocationFormatsProvider == null) throw new ArgumentNullException("viewLocationFormatsProvider"); _viewEngine = viewEngine; _viewLocationFormatsProvider = viewLocationFormatsProvider; }
/// <summary> /// Gets a view engine that is a clone of the given <paramref name="viewEngine"/> and has enhanced search locations. /// </summary> /// <param name="viewEngine">The view engine.</param> /// <param name="controller">The controller.</param> /// <param name="pathTransformations">Transformations that have to be applied to each view engine search path.</param> private static IViewEngine GetViewEngine(VirtualPathProviderViewEngine viewEngine, Controller controller, IList<Func<string, string>> pathTransformations) { var newEngine = (VirtualPathProviderViewEngine)Activator.CreateInstance(viewEngine.GetType()); newEngine.AreaViewLocationFormats = ControllerExtensions.AppendControllerVirtualPath(viewEngine.AreaViewLocationFormats, pathTransformations); newEngine.AreaMasterLocationFormats = ControllerExtensions.AppendControllerVirtualPath(viewEngine.AreaPartialViewLocationFormats, pathTransformations); newEngine.AreaPartialViewLocationFormats = ControllerExtensions.AppendControllerVirtualPath(viewEngine.AreaPartialViewLocationFormats, pathTransformations); newEngine.ViewLocationFormats = ControllerExtensions.AppendControllerVirtualPath(viewEngine.ViewLocationFormats, pathTransformations); newEngine.MasterLocationFormats = ControllerExtensions.AppendControllerVirtualPath(viewEngine.MasterLocationFormats, pathTransformations); newEngine.PartialViewLocationFormats = ControllerExtensions.AppendControllerVirtualPath(viewEngine.PartialViewLocationFormats, pathTransformations); return newEngine; }
public PrecompiledViewEngine(params Assembly[] assemblies) { LastInstance = this; _backupEngine = new RazorViewEngine(); AreaViewLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", }; AreaMasterLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", }; AreaPartialViewLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", }; FileExtensions = new[] { "cshtml", }; MasterLocationFormats = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", }; PartialViewLocationFormats = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", }; ViewLocationFormats = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", }; _views = new Dictionary<string, Type>(StringComparer.InvariantCultureIgnoreCase); foreach (var asm in assemblies) { List<Type> viewTypes; try { viewTypes = asm.GetTypes().Where(t => typeof(WebPageRenderingBase).IsAssignableFrom(t)).ToList(); } catch (Exception e) { throw e; } foreach (var view in viewTypes) { var attr = view.GetCustomAttribute<CompiledFromFileAttribute>(); if (attr != null) { _views[MakeVirtualPath(attr.SourceFile)] = view; } } } ViewPaths = _views.Keys.OrderBy(_ => _).ToList(); }