Add NonViewComponentAttribute
This commit is contained in:
parent
60d600dd5c
commit
261f73abc7
|
|
@ -0,0 +1,16 @@
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates that the type and any derived types that this attribute is applied to
|
||||||
|
/// is not considered a view component by the default view component discovery mechanism.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
|
||||||
|
public class NonViewComponentAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
||||||
{
|
{
|
||||||
|
|
@ -82,7 +83,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
||||||
if (!typeInfo.IsClass ||
|
if (!typeInfo.IsClass ||
|
||||||
!typeInfo.IsPublic ||
|
!typeInfo.IsPublic ||
|
||||||
typeInfo.IsAbstract ||
|
typeInfo.IsAbstract ||
|
||||||
typeInfo.ContainsGenericParameters)
|
typeInfo.ContainsGenericParameters ||
|
||||||
|
typeInfo.IsDefined(typeof(NonViewComponentAttribute)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Core;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewComponentConventionsTestClasses;
|
using Microsoft.AspNetCore.Mvc.ViewComponentConventionsTestClasses;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -41,6 +42,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
||||||
|
|
||||||
// Value types cannot be view components
|
// Value types cannot be view components
|
||||||
[InlineData(typeof(int), false)]
|
[InlineData(typeof(int), false)]
|
||||||
|
|
||||||
|
// If it has NonViewComponent it's not a view component
|
||||||
|
[InlineData(typeof(NonViewComponentAttributeViewComponent), false)]
|
||||||
|
[InlineData(typeof(ChildOfNonViewComponent), false)]
|
||||||
public void IsComponent(Type type, bool expected)
|
public void IsComponent(Type type, bool expected)
|
||||||
{
|
{
|
||||||
// Arrange & Act
|
// Arrange & Act
|
||||||
|
|
@ -125,6 +130,13 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponentConventionsTestClasses
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NonViewComponent]
|
||||||
|
public class NonViewComponentAttributeViewComponent
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public class ChildOfNonViewComponent : NonViewComponentAttributeViewComponent
|
||||||
|
{ }
|
||||||
|
|
||||||
public class NamingConventionViewComponent
|
public class NamingConventionViewComponent
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue