You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB
C#

12 months ago
using Microsoft.AspNetCore.Mvc.Controllers;
using System.Reflection;
namespace Ds.Module.DynamicApi
{
/// <summary>
///
/// </summary>
public class AutoAPIControllerFeatureProvider : ControllerFeatureProvider
{
//IApplicationFeatureProvider<ControllerFeature>, IApplicationFeatureProvider
//{
//public void PopulateFeature(IEnumerable<ApplicationPart> parts, ControllerFeature feature)
//{
// foreach (var part in parts.OfType<IApplicationPartTypeProvider>())
// {
// foreach (var type in part.Types)
// {
// if (IsController(type) && !feature.Controllers.Contains(type))
// {
// feature.Controllers.Add(type);
// }
// }
// }
//}
//protected override bool IsController(TypeInfo typeInfo)
protected override bool IsController(TypeInfo typeInfo)
{
//判断是否继承了指定的接口
if (typeof(IDsAutoAPIServices).IsAssignableFrom(typeInfo))
{
if (!typeInfo.IsInterface &&
!typeInfo.IsAbstract &&
!typeInfo.IsGenericType &&
typeInfo.IsPublic)
{
return true;
}
}
return false;
//return base.IsController(typeInfo);
}
}
}