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
/
ViewComponentDescriptor.cs
134 lines (121 loc) · 4.54 KB
/
ViewComponentDescriptor.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// 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 System.Diagnostics;
using System.Reflection;
namespace Microsoft.AspNetCore.Mvc.ViewComponents
{
/// <summary>
/// A descriptor for a view component.
/// </summary>
[DebuggerDisplay("{DisplayName}")]
public class ViewComponentDescriptor
{
private string _displayName;
/// <summary>
/// Creates a new <see cref="ViewComponentDescriptor"/>.
/// </summary>
public ViewComponentDescriptor()
{
Id = Guid.NewGuid().ToString();
}
/// <summary>
/// Gets or sets the display name of the view component.
/// </summary>
public string DisplayName
{
get
{
if (_displayName == null)
{
_displayName = TypeInfo?.FullName;
}
return _displayName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_displayName = value;
}
}
/// <summary>
/// Gets or sets the full name.
/// </summary>
/// <remarks>
/// <para>
/// The full name is defaulted to the full namespace of the view component class, prepended to
/// the class name with a '.' character as the separator. If the view component class uses
/// <code>ViewComponent</code> as a suffix, the suffix will be omitted from the <see cref="FullName"/>.
/// </para>
/// <example>
/// Class Name: Contoso.Products.LoginViewComponent
/// View Component FullName: Contoso.Products.Login
/// </example>
/// <example>
/// Class Name: Contoso.Blog.Tags
/// View Component FullName: Contoso.Blog.Tags
/// </example>
/// <para>
/// If <see cref="ViewComponentAttribute.Name"/> is used to set a name, then this will be used as
/// the <see cref="FullName"/>.
/// </para>
/// <example>
/// [ViewComponent(Name = "Contoso.Forum.UsersOnline")]
/// public class OnlineUsersViewComponent
/// {
/// }
/// View Component FullName: Contoso.Forum.UsersOnline
/// </example>
/// </remarks>
public string FullName { get; set; }
/// <summary>
/// Gets or set the generated unique identifier for this <see cref="ViewComponentDescriptor"/>.
/// </summary>
public string Id { get; set; }
/// <summary>
/// Gets or sets the short name.
/// </summary>
/// <remarks>
/// <para>
/// The short name is defaulted to the name of the view component class. If the view component class uses
/// <code>ViewComponent</code> as a suffix, the suffix will be omitted from the <see cref="ShortName"/>.
/// </para>
/// <example>
/// Class Name: Contoso.Products.LoginViewComponent
/// View Component ShortName: Login
/// </example>
/// <example>
/// Class Name: Contoso.Blog.Tags
/// View Component ShortName: Tags
/// </example>
/// <para>
/// If <see cref="ViewComponentAttribute.Name"/> is used to set a name, then the last segment of the
/// value (using '.' as a separate) will be used as the <see cref="ShortName"/>.
/// </para>
/// <example>
/// [ViewComponent(Name = "Contoso.Forum.UsersOnline")]
/// public class OnlineUsersViewComponent
/// {
/// }
/// View Component ShortName: UsersOnline
/// </example>
/// </remarks>
public string ShortName { get; set; }
/// <summary>
/// Gets or sets the <see cref="System.Reflection.TypeInfo"/>.
/// </summary>
public TypeInfo TypeInfo { get; set; }
/// <summary>
/// Gets or sets the <see cref="System.Reflection.MethodInfo"/> to invoke.
/// </summary>
public MethodInfo MethodInfo { get; set; }
/// <summary>
/// Gets or sets the parameters associated with the method described by <see cref="MethodInfo"/>.
/// </summary>
public IReadOnlyList<ParameterInfo> Parameters { get; set; }
}
}