/*********************************************************************** * Project: CoreCms.Net * * Web: https://CoreCms.Net * * ProjectName: 核心内容管理系统 * * Author: 大灰灰 * * Email: JianWeie@163.com * * Versions: 1.0 * * CreateTime: 2020-02-02 18:53:27 * NameSpace: CoreCms.Net.Framework.Swagger * FileName: CustomRouteAttribute * ClassDescription: ***********************************************************************/ using System; using System.Collections.Generic; using System.Text; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; namespace CoreCms.Net.Swagger { /// /// 自定义路由 /api/{version}/[controler]/[action] /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public class CustomRouteAttribute : RouteAttribute, IApiDescriptionGroupNameProvider { /// /// 分组名称,是来实现接口 IApiDescriptionGroupNameProvider /// public string GroupName { get; set; } /// /// 自定义路由构造函数,继承基类路由 /// /// public CustomRouteAttribute(string actionName = "[action]") : base("/api/{version}/[controller]/" + actionName) { } /// /// 自定义版本+路由构造函数,继承基类路由 /// /// /// public CustomRouteAttribute(CustomApiVersion.ApiVersions version, string actionName = "") : base($"/api/{version.ToString()}/[controller]/{actionName}") { GroupName = version.ToString(); } } }