// 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.Diagnostics;
using System.Reflection;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
///
/// A descriptor for a view component.
///
[DebuggerDisplay("{DisplayName}")]
public class ViewComponentDescriptor
{
private string _displayName;
///
/// Creates a new .
///
public ViewComponentDescriptor()
{
Id = Guid.NewGuid().ToString();
}
///
/// Gets or sets the display name of the view component.
///
public string DisplayName
{
get
{
if (_displayName == null)
{
_displayName = Type?.FullName;
}
return _displayName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_displayName = value;
}
}
///
/// Gets or sets the full name.
///
///
///
/// The full name is defaulted to the full namespace of the view component class, prepended to
/// the the class name with a '.' character as the separator. If the view component class uses
/// ViewComponent as a suffix, the suffix will be omitted from the .
///
///
/// Class Name: Contoso.Products.LoginViewComponent
/// View Component FullName: Contoso.Products.Login
///
///
/// Class Name: Contoso.Blog.Tags
/// View Component FullName: Contoso.Blog.Tags
///
///
/// If is used to set a name, then this will be used as
/// the .
///
///
/// [ViewComponent(Name = "Contoso.Forum.UsersOnline")]
/// public class OnlineUsersViewComponent
/// {
/// }
/// View Component FullName: Contoso.Forum.UsersOnline
///
///
public string FullName { get; set; }
///
/// Gets or set the generated unique identifier for this .
///
public string Id { get; set; }
///
/// Gets or sets the short name.
///
///
///
/// The short name is defaulted to the name of the view component class. If the view component class uses
/// ViewComponent as a suffix, the suffix will be omitted from the .
///
///
/// Class Name: Contoso.Products.LoginViewComponent
/// View Component ShortName: Login
///
///
/// Class Name: Contoso.Blog.Tags
/// View Component ShortName: Tags
///
///
/// If is used to set a name, then the last segment of the
/// value (using '.' as a separate) will be used as the .
///
///
/// [ViewComponent(Name = "Contoso.Forum.UsersOnline")]
/// public class OnlineUsersViewComponent
/// {
/// }
/// View Component ShortName: UsersOnline
///
///
public string ShortName { get; set; }
///
/// Gets or sets the .
///
public Type Type { get; set; }
///
/// Gets or sets the to invoke.
///
public MethodInfo MethodInfo { get; set; }
}
}