DocSpace-buildtools/common/ASC.Api.Core/Convention/ControllerNameAttributeConvention.cs

31 lines
805 B
C#

using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
namespace ASC.Api.Core.Convention
{
[AttributeUsage(AttributeTargets.Class)]
public class ControllerNameAttribute : Attribute
{
public string Name { get; }
public ControllerNameAttribute(string name)
{
Name = name;
}
}
public class ControllerNameAttributeConvention : IControllerModelConvention
{
public void Apply(ControllerModel controller)
{
var controllerNameAttribute = controller.Attributes.OfType<ControllerNameAttribute>().SingleOrDefault();
if (controllerNameAttribute != null)
{
controller.ControllerName = controllerNameAttribute.Name;
}
}
}
}