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
/
MvcViewOptions.cs
108 lines (98 loc) · 4.6 KB
/
MvcViewOptions.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Microsoft.AspNetCore.Mvc
{
/// <summary>
/// Provides programmatic configuration for views in the MVC framework.
/// </summary>
public class MvcViewOptions : IEnumerable<ICompatibilitySwitch>
{
private readonly CompatibilitySwitch<bool> _suppressTempDataAttributePrefix;
private readonly ICompatibilitySwitch[] _switches;
private HtmlHelperOptions _htmlHelperOptions = new HtmlHelperOptions();
public MvcViewOptions()
{
_suppressTempDataAttributePrefix = new CompatibilitySwitch<bool>(nameof(SuppressTempDataAttributePrefix));
_switches = new[]
{
_suppressTempDataAttributePrefix,
};
}
/// <summary>
/// Gets or sets programmatic configuration for the HTML helpers and <see cref="Rendering.ViewContext"/>.
/// </summary>
public HtmlHelperOptions HtmlHelperOptions
{
get => _htmlHelperOptions;
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_htmlHelperOptions = value;
}
}
/// <summary>
/// <para>
/// Gets or sets a value that determines if the <see cref="ITempDataDictionary"/> keys for
/// properties annotated with <see cref="TempDataAttribute"/> include the prefix <c>TempDataProperty-</c>.
/// </para>
/// <para>
/// When <see cref="TempDataAttribute.Key"/> is not specified, the lookup key for properties annotated
/// with <see cref="TempDataAttribute"/> is derived from the property name. In releases prior to ASP.NET Core 2.1,
/// the calculated key was the property name prefixed by the value <c>TempDataProperty-</c>.
/// e.g. <c>TempDataProperty-SuccessMessage</c>. When this option is <c>true</c>, the calculated key for the property is
/// the property name e.g. <c>SuccessMessage</c>.
/// </para>
/// <para>
/// Defaults to <c>false</c>.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks>
public bool SuppressTempDataAttributePrefix
{
get => _suppressTempDataAttributePrefix.Value;
set => _suppressTempDataAttributePrefix.Value = value;
}
/// <summary>
/// Gets a list <see cref="IViewEngine"/>s used by this application.
/// </summary>
public IList<IViewEngine> ViewEngines { get; } = new List<IViewEngine>();
/// <summary>
/// Gets a list of <see cref="IClientModelValidatorProvider"/> instances.
/// </summary>
public IList<IClientModelValidatorProvider> ClientModelValidatorProviders { get; } =
new List<IClientModelValidatorProvider>();
IEnumerator<ICompatibilitySwitch> IEnumerable<ICompatibilitySwitch>.GetEnumerator()
{
return ((IEnumerable<ICompatibilitySwitch>)_switches).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator();
}
}