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
/
ViewDataDictionaryOfT.cs
95 lines (89 loc) · 4.08 KB
/
ViewDataDictionaryOfT.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
// 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 Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
public class ViewDataDictionary<TModel> : ViewDataDictionary
{
/// <summary>
/// Initializes a new instance of the <see cref="ViewDataDictionary{TModel}"/> class.
/// </summary>
/// <remarks>
/// For use when creating a <see cref="ViewDataDictionary{TModel}"/> for a new top-level scope.
/// </remarks>
/// <inheritdoc />
// References may not show up due to Type.GetConstructor() use in RazorPageActivator.
public ViewDataDictionary(
IModelMetadataProvider metadataProvider,
ModelStateDictionary modelState)
: base(metadataProvider, modelState, declaredModelType: typeof(TModel))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ViewDataDictionary{TModel}"/> class based in part on an
/// existing <see cref="ViewDataDictionary"/> instance.
/// </summary>
/// <remarks>
/// <para>
/// For use when copying a <see cref="ViewDataDictionary"/> instance and <typeparamref name="TModel"/> is known
/// but <see cref="Model"/> should be copied from the existing instance e.g. when copying from a base
/// <see cref="ViewDataDictionary"/> instance to a <see cref="ViewDataDictionary{TModel}"/> instance.
/// </para>
/// <para>
/// This constructor may <c>throw</c> if <c>source.Model</c> is non-<c>null</c> and incompatible with
/// <typeparamref name="TModel"/>. Pass <c>model: null</c> to
/// <see cref="ViewDataDictionary{TModel}(ViewDataDictionary, object)"/> to ignore <c>source.Model</c>.
/// </para>
/// </remarks>
/// <inheritdoc />
// References may not show up due to Type.GetConstructor() use in RazorPageActivator.
public ViewDataDictionary(ViewDataDictionary source)
: base(source, declaredModelType: typeof(TModel))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ViewDataDictionary{TModel}"/> class based in part on an
/// existing <see cref="ViewDataDictionary"/> instance. This constructor is careful to avoid exceptions
/// <see cref="ViewDataDictionary.SetModel"/> may throw when <paramref name="model"/> is <c>null</c>.
/// </summary>
/// <remarks>
/// <para>
/// For use when copying a <see cref="ViewDataDictionary"/> instance and <typeparamref name="TModel"/> and
/// <see cref="Model"/> are known.
/// </para>
/// <para>
/// This constructor may <c>throw</c> if <paramref name="model"/> is non-<c>null</c> and incompatible with
/// <typeparamref name="TModel"/>.
/// </para>
/// </remarks>
/// <inheritdoc />
// Model parameter type is object to allow "model: null" calls even when TModel is a value type. A TModel
// parameter would likely require IEquatable<TModel> type restrictions to pass expected null value to the base
// constructor.
public ViewDataDictionary(ViewDataDictionary source, object model)
: base(source, model, declaredModelType: typeof(TModel))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ViewDataDictionary{TModel}"/> class.
/// </summary>
/// <remarks>Internal for testing.</remarks>
/// <inheritdoc />
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
: base(metadataProvider, declaredModelType: typeof(TModel))
{
}
/// <inheritdoc />
public new TModel Model
{
get
{
return (base.Model == null) ? default(TModel) : (TModel)base.Model;
}
set
{
base.Model = value;
}
}
}
}