This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
CompiledViewDescriptor.cs
91 lines (78 loc) · 3.38 KB
/
CompiledViewDescriptor.cs
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
// 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 Microsoft.AspNetCore.Mvc.Razor.Internal;
using Microsoft.AspNetCore.Razor.Hosting;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
{
/// <summary>
/// Represents a compiled Razor View or Page.
/// </summary>
public class CompiledViewDescriptor
{
/// <summary>
/// Creates a new <see cref="CompiledViewDescriptor"/>.
/// </summary>
public CompiledViewDescriptor()
{
}
/// <summary>
/// Creates a new <see cref="CompiledViewDescriptor"/>. At least one of <paramref name="attribute"/> or
/// <paramref name="item"/> must be non-<c>null</c>.
/// </summary>
/// <param name="item">The <see cref="RazorCompiledItem"/>.</param>
/// <param name="attribute">The <see cref="RazorViewAttribute"/>.</param>
public CompiledViewDescriptor(RazorCompiledItem item, RazorViewAttribute attribute)
{
if (item == null && attribute == null)
{
// We require at least one of these to be specified.
throw new ArgumentException(Resources.FormatCompiledViewDescriptor_NoData(nameof(item), nameof(attribute)));
}
Item = item;
//
// For now we expect that MVC views and pages will still have either:
// [RazorView(...)] or
// [RazorPage(...)].
//
// In theory we could look at the 'Item.Kind' to determine what kind of thing we're dealing
// with, but for compat reasons we're basing it on ViewAttribute since that's what 2.0 had.
ViewAttribute = attribute;
// We don't have access to the file provider here so we can't check if the files
// even exist or what their checksums are. For now leave this empty, it will be updated
// later.
ExpirationTokens = Array.Empty<IChangeToken>();
RelativePath = ViewPath.NormalizePath(item?.Identifier ?? attribute.Path);
IsPrecompiled = true;
}
/// <summary>
/// The normalized application relative path of the view.
/// </summary>
public string RelativePath { get; set; }
/// <summary>
/// Gets or sets the <see cref="RazorViewAttribute"/> decorating the view.
/// </summary>
/// <remarks>
/// May be <c>null</c>.
/// </remarks>
public RazorViewAttribute ViewAttribute { get; set; }
/// <summary>
/// <see cref="IChangeToken"/> instances that indicate when this result has expired.
/// </summary>
public IList<IChangeToken> ExpirationTokens { get; set; }
/// <summary>
/// Gets a value that determines if the view is precompiled.
/// </summary>
public bool IsPrecompiled { get; set; }
/// <summary>
/// Gets the <see cref="RazorCompiledItem"/> descriptor for this view.
/// </summary>
public RazorCompiledItem Item { get; set; }
/// <summary>
/// Gets the type of the compiled item.
/// </summary>
public Type Type => Item?.Type ?? ViewAttribute?.ViewType;
}
}