-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathProfiledVirtualPathProviderViewEngine.cs
More file actions
38 lines (32 loc) · 1.42 KB
/
ProfiledVirtualPathProviderViewEngine.cs
File metadata and controls
38 lines (32 loc) · 1.42 KB
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
using System;
using System.Web.Mvc;
using System.Web.WebPages;
namespace StackExchange.Precompilation
{
/// <summary>
/// Base class for implementing <see cref="VirtualPathProviderViewEngine"/> derived types that provide custom profiling steps.
/// </summary>
public abstract class ProfiledVirtualPathProviderViewEngine : VirtualPathProviderViewEngine
{
/// <summary>
/// Triggers when the engine performs a step that can be profiled.
/// </summary>
public Func<string, IDisposable> ProfileStep { get; set; }
internal IVirtualPathFactory VirtualPathFactory => _virtualPathFactoryFactory.Value;
protected abstract IVirtualPathFactory CreateVirtualPathFactory();
private readonly Lazy<IVirtualPathFactory> _virtualPathFactoryFactory; // sorry, I had to...
/// <inheritdoc />
protected ProfiledVirtualPathProviderViewEngine()
{
_virtualPathFactoryFactory = new Lazy<IVirtualPathFactory>(CreateVirtualPathFactory);
}
}
internal static class ProfileVirtualPathProviderViewEngineExtensions
{
/// <summary>
/// Invokes the <see cref="ProfiledVirtualPathProviderViewEngine.ProfileStep"/> if it's set.
/// </summary>
public static IDisposable DoProfileStep(this ProfiledVirtualPathProviderViewEngine instance, string name) =>
instance?.ProfileStep?.Invoke(name);
}
}